Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# Create the lists of things to choose from
verbs = ['eat', 'speak', 'kick', 'punch', 'yell']
fruit = ['apples', 'oranges', 'pears', 'grapes', 'bananas', 'mangos']
time_of_day = ['morning', 'afternoon', 'evening', 'dusk', 'dawn']
# Run this code until the user hits `Control-C` on her keyboard.
while True:
# Ask the user for various inputs
user_verb = input("\nPick a number between 0 and 4: ")
user_fruit = input("Now pick a number between 0 and 5: ")
user_time_of_day = input("Now pick another number between 0 and 4" \
" but different than your first: ")
user_fav_activity = input("What is your favorite activity?: ")
# Convert the inputs to integers
user_verb = int(user_verb)
user_fruit = int(user_fruit)
user_time_of_day = int(user_time_of_day)
# If the user entered the same number for time of day and verb, yell at him and exit
if user_time_of_day == user_verb:
print("Hey! I told you to pick a different number between 0 and 4!")
print("I'm done. Goodbye.")
break
# Assuming everything worked, print out the inane sentence.
# Use the integer values the user input to select the element in the lists
# Oh yeah, the position of the first element in a Python list is 0, not 1
print("Oh yeah! I love to {} {} in the {} while I'm {}! \n" \
.format(verbs[user_verb],
fruit[user_fruit],
time_of_day[user_time_of_day],
user_fav_activity))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment