-2
import random

def headsortails():
  random_side = random.randint (0,1)
  if random_side == (0):
   print("Heads")
  else:
    print("Tails") 

answer_yes = "Yes" .lower()
answer_no = "No" .lower() 


heads_or_tails = input("\n\nLets do 'Heads or tails'. I got a binary coin right here \n\nHeads = 0\nTails = 1\n\n[Press Enter]")

tosscoin = input("\nTo toss coin and choice type 0 or 1: ")
tosscoin = "0", "1"


print("Revealing coin... *rolling drums*\n") 

(headsortails())

again = input("\nDo you want to play again? [Enter Yes/No]) ") 
if again == (answer_yes):
  print (heads_or_tails)

I have already defined heads_or_tails but it wont print it after I answer yes. Also, is there a way to write a string that I can combine with the new print?

iB5Y
  • 3
  • 1
  • Improve the first chunk on your code! [Random Boolean](https://stackoverflow.com/questions/6824681/get-a-random-boolean-in-python) – Lukas Kaspras Mar 01 '21 at 16:07
  • Please clarify what is wrong with your code. I don't see a question here – Tomerikoo Mar 01 '21 at 16:07
  • There are a dozend or so not nessesary things in your code - parenthesis, and stuff that makes no sense (like asking via input for `tosscoin` then immediately overwriting it by a tuple of `'0','1'` - you might want to take a llook at a good tutorial and reasearch PEP-8 for Code formatting. – Patrick Artner Mar 01 '21 at 16:08

2 Answers2

0

You need a loop to repeat code:

import random

def headsortails():
  random_side = random.randint(0, 1)
  if random_side == 0:
    print("Heads")
  else:
    print("Tails") 

answer_yes = "Yes".lower()
answer_no = "No".lower() 

while True:
  heads_or_tails = input("\n\nLets do 'Heads or tails'. I got a binary coin right here \n\nHeads = 0\nTails = 1\n\n[Press Enter]")

  tosscoin = input("\nTo toss coin and choice type 0 or 1: ")
  tosscoin = "0", "1"


  print("Revealing coin... *rolling drums*\n") 

  headsortails()

  again = input("\nDo you want to play again? [Enter Yes/No]) ") 
  if again != answer_yes:
    break
Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
0

input(prompt_string) stores the value that you inputted after the prompt has been printed. When you print heads_or_tails on the last line, you didn't ask for another prompt, instead you're just going to print the value that you stored on heads_or_tails. You can make it work using while looping like this:

import random

def headsortails():
    random_side = random.randint (0,1)
    if random_side == (0):
        print("Heads")
    else:
        print("Tails") 

while True:
    answer_yes = "Yes" .lower()
    answer_no = "No" .lower() 
    heads_or_tails = input("\n\nLets do 'Heads or tails'. I got a binary coin right here \n\nHeads = 0\nTails = 1\n\n[Press Enter]")

    tosscoin = input("\nTo toss coin and choice type 0 or 1: ")
    tosscoin = "0", "1"


    print("Revealing coin... *rolling drums*\n") 

    headsortails()

    again = input("\nDo you want to play again? [Enter Yes/No]) ") 
    if again == (answer_no):
        break