Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 1. Create a program that produces a random integer between 15 and 35.
- 2. Below is a list of five items of food, create some code that shuffles the list,
- prints the shuffled list, then picks and prints one item at random.
- food = [“beans”,”cheese”,”tofu”,”cod”,”halumi”]
- 3. Create a program that keeps asking for a random number between 1 and 52, until “xxx”
- is entered and then tells you how many were even numbers and how many were odd numbers. (hint below if needed)
- 4. Take the list from Q2 and create a program that asks the user to enter a
- new food item twice and then adds them to the list. Then shuffles the list, removes the last item,
- shuffles until the list is empty, print out the items removed each time. (hint below if needed)
- 5. Create two lists, one of action words (verbs) and one of (fist_names).
- Then create a program that selects a random item from each list, then concatenates them to give the
- name of a new superhero and create five superhero names. Append the names created to a new list.
- """
- """
- #1
- import random
- print(random.randint(15,35))
- """
- """
- #2
- import random
- food = ["beans","cheese","tofu","cod","halumi"]
- print(food)
- random.shuffle(food)
- print(food)
- print(random.choice(food))
- """
- """
- #3
- import random
- even = 0
- odd = 0
- trig = ""
- while trig != "xxx":
- trig = input("Press enter to get a random number >> ")
- if trig != "xxx":
- num = (random.randint(1,52))
- print(num)
- if num%2 == 0:
- even = even +1
- else:
- odd = odd +1
- print(odd)
- print(even)
- """
- """
- #4
- import random
- food = ["beans","cheese","tofu","cod","halumi"]
- for i in range(2):
- new_item = input("Please enter new item >> ")
- food.append(new_item)
- for i in range(len(food)):
- print("BS",food)
- random.shuffle(food)
- print("AS",food)
- print("last item", food[-1])
- food.pop()
- print(food)
- """
- """
- # 5
- import random
- verb = ["running","sitting","crying","laughing","shouting"]
- first_names = ["Henry","Claire","Clare","Sean","Jimbob","Hazel"]
- super_heros = []
- for i in range(5):
- new_hero = random.choice(verb) + " " + random.choice(first_names)
- super_heros.append(new_hero)
- print(new_hero, super_heros)
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement