- 1

Can someone help me please with this exercise in python

Write a program which picks a random card from a standard deck, until # you tell it to stop. # Your program will use a while true loop. Every time the loop runs, it # will display a random number between 1 and 10, or jack, queen, king; # and a suit-heart,clubs,spades or diamonds. # Then it should ask you if you want to pick another random card. Use # what the user types to figure out whether to break out of the loop, # or to repeat again.

16th Feb 2017, 1:07 AM
JOhn
JOhn - avatar
2 odpowiedzi
+ 9
import random def stop(): global check inp=input("input stop to stop. input anything else to draw a card.") if inp == "stop": check=False else: pass def draw(): num=random.randint(1,13) if num < 11: print("you drew a:", num) elif num == 11: print("you drew a: jack") elif num == 12: print("you drew a: queen") else: print("you drew a: king") symbol=["suit-heart", "clubs", "spades", "diamonds"] print("it is a:", random.choice(symbol)) check=True while check == True: stop() draw() # there, I did your homework for free. now scram!
16th Feb 2017, 3:08 AM
Ahri Fox
Ahri Fox - avatar
- 1
Haha thanks! I haven't gotten to defining classes yet but I can get an idea of how the program should look.
16th Feb 2017, 1:31 PM
JOhn
JOhn - avatar