2023. 2. 24. 10:52ㆍ개인적인 공부/Python
Random 을 이용한 동전 앞뒤
Instructions
You are going to write a virtual coin toss program. It will randomly tell the user "Heads" or "Tails".
Important, the first letter should be capitalised and spelt exactly like in the example e.g. Heads, not heads.
There are many ways of doing this. But to practice what we learnt in the last lesson, you should generate a random number, either 0 or 1. Then use that number to print out Heads or Tails.
e.g. 1 means Heads 0 means Tails
Example Output
Heads
or
Tails
When you're happy with your code, click submit.
Testing Your Code
Check your code is doing what it is supposed to. When you're happy with your code, click submit to check your solution. Your program may look like it is failing the tests when it isn't. We're using the random functionality in this exercise, so the tests will match different outcomes.
import random
#Remember to use the random module -- 랜덤 모듈을 써라.
#Hint: Remember to import the random module here at the top of the file. 🎲 import Random 을 해라
#Write the rest of your code below this line 👇
# print("Heads or Tails? : ") -- 이것은 해도 상관없으나 여기서는 요구하는 것이 아니라서 없어야 함.
Head_or_Tails = random.randint(0,1)
if Head_or_Tails == 0:
print("Heads")
else:
print("Tails")
'개인적인 공부 > Python' 카테고리의 다른 글
day 4-4 python (roulette, 룰렛) (0) | 2023.02.24 |
---|---|
day 4-3 python (list, 리스트) (0) | 2023.02.24 |
day 4-1 python (Randomisation), 무작위화 (0) | 2023.02.23 |
day 3-9 python 사랑계산기, (Love Calculator) (1) | 2023.02.23 |
day 3-8 python (논리 연산자) (0) | 2023.02.22 |