|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
need help newbie
print 'welcome to greek eatery'
print 'we are full \n ' money = int(raw_input('how much to tip ?')) if money: print 'we have a table' else: print 'sit down and wait' raw_input('press the enter key to exit') # i want the program to display 'we have a table' if i enter a $ amount # and display 'sit down and wait' if i enter o |
|
#2
|
||||
|
||||
|
All you had to do was finish your "if" statement.You litterally said "if money" and that was all hehe.You need to define the "if" check on money.So in your case it would be if money is greater than zero
Code:
if money > 0: Basicly your "if" check has to be something that can be answered yes or no,so that you can act accordingly.The very basic idea being: Code:
if this is true:
do this
else:
do that
And since you already know about typecasting,you can make a built-in error message if the input can't be typecast as a integer.Since this was kinda fun I got fancy and wrapped it inside a "while true" loop,so if there was a VauleError it would loop until you put in a integer Code:
print 'Welcome To The Greek Eatery!'
print 'Unfortunately we are full right now...'
print '*wink* *wink*'
print '*extends hand*\n'
while True: #start the loop
try: #try to typecast the input and then act on it
money = int(raw_input('How much of a "tip" do you give?'))
if money > 0:
print 'A table has just become available.'
print 'Right this way,Sir...'
break #break out of the loop
else:
print 'Take a seat in the waiting area,Bub!'
break #break out of the loop
except ValueError: #if the input isn't a integer
print "\nInvaild Amount!\n"
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > need help newbie |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|