개인적인 공부/Python

day 4-2 python (Head or Tails), 동전 앞 뒤

karatejin 2023. 2. 24. 10:52

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")

 

 

Heads and Tails 만 Output 하게 해야한다.