Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 8th, 2004, 07:02 PM
perfect20002 perfect20002 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 28 perfect20002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old April 8th, 2004, 08:17 PM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 2 h 12 m
Reputation Power: 5
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?!?!?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > need help newbie


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway