Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8096457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:27:21+00:00 2026-06-05T21:27:21+00:00

from random import * while True: random1 = randint(1,20) random2 = randint(1,20) print(h =

  • 0
from random import *

while True:

    random1 = randint(1,20)

    random2 = randint(1,20)

    print("h = higher, l = lower, s = same, q = quit")

    print(random1)

    a = input()

    if a.lower() == 'q':
            break

    print(random2)

    if a.lower() == 'h' and random1 < random2:

        print("Well done")

    elif a.lower() == 'l' and random1 > random2:

        print("Well done")

    elif a.lower() == 's' and random1 == random2:

        print("Well done")
    else:

        print("Loser")

So what I am trying to do is have x as my score. And when the answer prints “Well Done” I would like it to add 10 points to my score and then print the score. The thing is the score seems to reset loads of times throughout the game and I would like it to either add 10 to the score or stay the same. Does anyone know a way of doing this in my program. I can’t imagine it would be too hard but I am only a beginner and still learning. At the moment I have no score at all added to my program, just so you can show me the easiest/ best way too approach this. Thanks for the help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:27:22+00:00Added an answer on June 5, 2026 at 9:27 pm
    x = 0 # initialize the score to zero before the main loop
    while True:
    
        ...
    
        elif a.lower() == 's' and random1 == random2:
            x += 10 # increment the score
            print("Well done. Your current score is {0} points".format(x))
    

    anyway, the whole code could be shortened to:

    from random import *
    x = 0
    while True:
        random1 = randint(1,20)
        random2 = randint(1,20)
        print("h = higher, l = lower, s = same, q = quit")
        print(random1)
        a = input().lower()
        if a == 'q':
            break
    
        print(random2)
    
        if ((a == 'h' and random1 < random2) or
            (a == 'l' and random1 > random2) or
            (a == 's' and random1 == random2)):
            x += 10
            print("Well done. Your current score is: {0}".format(x))
        else:
            print("Loser")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from sys import exit from random import randint class Map(object): def death(): print quips[randint
here is my script: from random import * from turtle import * while True:
from random import uniform prob = [0.25,0.30,0.45] def onetrial(prob): u=uniform(0,1) if 0 < u
I am creating a random ID using the below code: from random import *
I have some question about functions which have default parameters. import sys from random
This loop help get some text data from web service: while True: u =
from random import randrange data = [(randrange(8), randrange(8)) for x in range(8)] And we
I have a list L composed from random numbers (defvar L '(1 4 2
I'm using Java to parse HTML from a random website, let's say it's http://google.com
I'm trying to return the message field from a random DB entry (in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.