python3: how do i ask a user for input to select a specific list, and then print the items in that specific list in a random order? and then repeat the program to ask the user if which list they would like to select
#lists of healthy food
Fruits = ['apples', 'oranges', 'pears']
Vegies = ['carrots', 'tomatoes', 'broccoli']
#lists of meats
Red_meat = ['steak', 'hamburgers']
White_meat = ['chicken', 'turkey']
import random
the code i have below just looks repetitive and annoying. there must be an easier way to print this as a string of text
****i would like to have the user asked for input (which list would you like to select from?****
#Healthy foods #
#then print out something along the lines of
OUTPUT: oranges, tomatoes, pears, carrots
print(random.choice(Fruits), end= " ")
print(random.choice(Vegies), end= " ")
print(random.choice(Fruits), end= " ")
print(random.choice(Vegies), end= " ")
then ask the user if it would like to run the same list again, or select a different list
#would you like to run this same list(yes or no)
if yes: (runs again)
if no: (Which list would you like to run?)
lists of meats:
print(random.choice(Red_meat), end= " ")
print(random.choice(White_meat), end= " ")
print(random.choice(Red_meat), end= " ")
print(random.choice(White_meat), end= " ")
OUTPUT: steak, turkey, hamburgers, chicken
again?
OUTPUT: hamburgers, chicken, steak, chicken
Aucun commentaire:
Enregistrer un commentaire