19 Jan 2015

Number Guessing game

#Python

'''
Number Guessing Game
'''



 

print "Please think of a number between 0 and 100!"
start=0
end=100
guess=50
while(1):
    print "Is your secret number",guess, "?"
    rd=raw_input("Enter 'h' to indicate the guess ls too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
    if(rd <>'c' and rd <>'l' and  rd<>'h'):
        print "Sorry, I did not understand your input."
    elif(rd=='c'):
        print "Game over. Your secret number was:", guess
        break
    elif(rd=='h'):
        end=guess
        guess=(start+end)/2
    else:
        start=guess
        guess=(start+end)/2   
   

Categories: , , ,

Related Posts:

  • Semordnilap using Recursion #PYTHON '''A semordnilap is a word or a phrase that spells a different word when backwards ("semordnilap" is a semordnilap of "palindromes"). Here are some examples:    nametag / gateman    do… Read More
  • Tower of Hanoi #Python ''' Recursive program to implement Tower of Hanoi for n rings and 3 stacks ''' def printMove(fr, to):    print('move from ' + str(fr) + ' to ' + str(to))def Towers(n, fr, to, spare):   … Read More
  • Monthly Payment of a Credit Card #Python #Program to calculate minimum Monthly Payment of a Credit Cardbalance = 3329annualInterestRate = 0.2minimumMonthlyPay=100newbalance=balancei=1monthlyInterestRate=annualInterestRate/12.0while(i<=12):  &… Read More
  • Receipt of Credit Card #Python #Program to calculate receipt of a Credit Card balance = 4842annualInterestRate = 0.2monthlyPaymentRate = 0.04totalPaid=0.0 i=1while(i<=12):    monthlyInterestRate=annualInterestRate/12.0&… Read More
  • Minimum Monthly Payment of Credit Card using Bisection Search #Python ''' Program to calculate minimum Monthly Payment of a Credit Card using Bisection Search ''' balance = 320000annualInterestRate = 0.2newbalance=balancei=1monthlyInterestRate=annualInterestRate/12.0lowerb=newbalan… Read More

0 comments:

Post a Comment

Copyright © 2025 UPgradeCODING | Powered by Blogger