Advertisement
namchef

LPTHW_ex14

Sep 27th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. ## extra credit
  2. ##Change the prompt variable to something else entirely.
  3. ## Add another argument and use it in your script.
  4.  
  5. from sys import argv
  6.  
  7. script, user_name, no_questions = argv
  8. prompt = '> '
  9.  
  10. print "Hi %s, I'm the %s script." % (user_name, script)
  11. print "I'd like to ask you a few questions."
  12.  
  13. i=['like', 'live', 'comp']
  14. def ask(x):
  15.     if x=='like':
  16.         print "Do you like me %s?" % user_name
  17.         likes = raw_input(prompt)
  18.     elif x=='live':
  19.         print "Where do you live %s ?" % user_name
  20.         lives=raw_input(prompt)
  21.     elif x=='comp':
  22.         print "What kind of computer do you have?"
  23.         computer = raw_input(prompt)
  24.  
  25. b=int(no_questions)
  26. for j in range(0,b):
  27.     x=i[j]
  28.     ask(x)
  29.  
  30. print "That's all, folks!"
  31.  
  32. # print """
  33. # Alright, so you said %r about liking me.
  34. # You live in %r. Not sure where that is.
  35. # And you have a %r computer. Nice.
  36. # """ % (likes, lives, computer)
  37.  
  38.  
  39. #win python shell
  40. # >>> import sys
  41. # >>> sys.argv=['','Ha','2']
  42. # >>> execfile('ex14.py')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement