Python Forum
How to start the program from the beginning.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to start the program from the beginning.
#1
Hey guys,

im currently just trying to make very basic rock, paper, scissors game but i strumbled upon the following problem:

i wrote basic code to play Rock, Paper, Scissors. After every round i call the playagain() function to ask the user, if he wants to play again. If he does, i want the code to start over again.

Heres my Code:

import random



# user input
# random cpu for R,S,P
# compare results
# print winner
# Ask to play again

def playagain():
    print("do you want to play again?")
    choose = input("Yes or No?")
    choose = choose.upper()
    if choose == "YES":
        print("a") # THE PROBLEM IS HERE: IF THE USER INPUT EQUALS "YES", THEN START FROM THE BEGINNING
    else:
        exit()


# cpu options to randomly choose
options = ["R", "P", "S"]
cpu = [i for i in random.choice(options)]
cpu = cpu[0]

user = input("Choose [R]ock, [P]aper or [S]cissors: ").upper()

# What if user gives wrong input?
while user not in options:
    user = input("Choose [R]ock, [P]aper or [S]cissors: ").upper()

if cpu == user:
    print("Draw!")
elif user == "R" and cpu == "S":
    print("You Win!")
    playagain()
elif user == "R" and cpu == "P":
    print("Fucking looser. You Suck!")
    playagain()
elif user == "P" and cpu == "R":
    print("You Win!")
    playagain()
elif user == "P" and cpu == "S":
    print("you fucking suck!")
    playagain()
elif user == "S" and cpu == "R":
    print("you suck!")
    playagain()
elif user == "S" and cpu == "P":
    print("You Win!")
    playagain()
thanks ahead! Heart
Reply


Messages In This Thread
How to start the program from the beginning. - by iamaghost - Feb-22-2021, 05:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Just beginning dalekeel 2 285 Apr-15-2024, 11:49 AM
Last Post: Pedroski55
  Program doesnt return beginning bilisim19 2 962 Feb-15-2023, 06:23 PM
Last Post: Larz60+
  List of dataframe values beginning with x,y or z glidecode 3 1,982 Nov-08-2021, 10:16 PM
Last Post: glidecode
  Start my program in RPI4B from SSH and Failed ATARI_LIVE 3 3,564 Nov-11-2020, 11:19 AM
Last Post: ATARI_LIVE
  Problem: Once I cancel the process my program will start working! Hadad 0 1,670 Jul-24-2019, 04:09 PM
Last Post: Hadad
  want to change the beginning of the result Rudinirudini 5 3,636 Nov-15-2018, 11:28 AM
Last Post: Rudinirudini
  How can I start a python program out of a python program? peer 3 2,345 Oct-30-2018, 05:07 PM
Last Post: Larz60+
  What's the difference b/w assigning start=None and start=" " Madara 1 2,347 Aug-06-2018, 08:23 AM
Last Post: buran
  Beginning of Beginner Help: Should I start with Python? appdevelnewb 2 3,098 Jul-23-2018, 11:17 PM
Last Post: appdevelnewb
  Wrap from end to beginning. 27 to 1, 28 to 2 etc DreamingInsanity 5 3,736 Jun-24-2018, 01:02 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020