Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help] Beginner's code
#1
Hey there, started learning today and i'm currently trying to make an '8 ball' from a challenge online.
I'm trying to make it so when the player says NOT to terminate the program, and keep the game going, it will return to the starting point.
Also, would love to get some advice on how to get the code more efficient and tidy for the future :)

import random
import time

list = ["It is certain",
           "It is decidedly so",
           "Without a doubt",
           "Yes definitely",
           "You may rely on it",
           "As I see it", " yes",
           "Most likely",
           "Outlook good",
           "Yes",
           "Signs point to yes",
           "Reply hazy try again",
           "Ask again later",
           "Better not tell you now",
           "Cannot predict now",
           "Concentrate and ask again",
           "Don't count on it",
           "My reply is no",
           "My sources say no",
           "Outlook not so good",
           "Very doubtful"]
int = 1
def Interface():
    print("Calculating..")
    time.sleep(3)
    return ("\n" + random.choice(list) + "\n")

while True:
    if int == 1:
        print("Start a new game by and ask a question")
        user_input = input("> ")
        if user_input[-1] != "?":
            print("You should ask in a form of a question..")
        else:
            print(Interface())
            int += 1
    if int != 1:
        print("Finish the game? (Yes/No)")
        user_answer = input("> ")
        if (user_answer.lower() == "yes"):
            print("Goodbye")
            break;
        if (user_answer.lower() == "no"):
            int == 1 
            
Reply


Messages In This Thread
[Help] Beginner's code - by Owenix - Sep-15-2018, 04:47 PM
RE: [Help] Beginner's code - by Gribouillis - Sep-15-2018, 05:14 PM
RE: [Help] Beginner's code - by Owenix - Sep-15-2018, 05:17 PM
RE: [Help] Beginner's code - by ichabod801 - Sep-15-2018, 08:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 840 May-19-2023, 11:19 AM
Last Post: deanhystad
  Code not reading http link from .txt file (Beginner level) plarrip 3 2,440 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Beginner: I need help understanding few lines of a code. hop_090 1 1,711 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,795 Jun-18-2020, 04:59 PM
Last Post: QTPi
  A beginner code... TheDude 7 3,319 Jun-18-2020, 05:39 AM
Last Post: TheDude
  [Beginner] Code is not producing desired result fakej171 2 2,455 Mar-21-2020, 10:26 AM
Last Post: buran
  what function should i use to tidy up my code (extreme beginner) scraig0117 4 2,318 Dec-16-2019, 04:03 PM
Last Post: scraig0117
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,442 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Beginner trying to code in python RA0211 1 1,861 Sep-26-2019, 11:10 AM
Last Post: emryscass
  Beginner Code bh3282 9 4,581 Mar-18-2019, 03:58 PM
Last Post: samsonite

Forum Jump:

User Panel Messages

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