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 8073097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:13:43+00:00 2026-06-05T14:13:43+00:00

Here’s the code: from random import * numbers = [‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′,’10’] r1 = choice (numbers)

  • 0

Here’s the code:

from random import *
numbers = ['0','1','2','3','4','5','6','7','8','9','10']
r1 = choice (numbers)
r2 = choice (numbers)
print("H = HIGHER ,, L = LOWER ,, S = SAME")
print(r1)
a = input()
print(r2)
if r2 == r1 and a == 's':
     print("well done")
if r2 < r1 and a == 'l':
     print("well done")
if r2 > r1 and a == 'h':
     print("well done")
else:
     print("unlucky")

The problem is the very last part of the script. everything works perfectly except at the end of the script just after print(r2)…. It all works but the answer keeps switching between “well done” and “unlucky”. Sometimes it says both. Does anyone know what the problem is? My assumption that this was happening because of the simple reason it is random, and the first output (r1) changes as we move along the script. Any suggestions?

  • 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-05T14:13:45+00:00Added an answer on June 5, 2026 at 2:13 pm

    This is a fully functioning version of your program:

    from random import choice
    
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
    
    r1 = choice(numbers)
    r2 = choice(numbers)
    
    print("h = HIGHER ,, l = LOWER ,, s = SAME")
    print(r1)
    a = raw_input()
    print(r2)
    
    if r2 == r1 and a == 's':
        print("well done")
    elif r2 < r1 and a == 'l':
        print("well done")
    elif r2 > r1 and a == 'h':
        print("well done")
    else:
        print("unlucky")
    

    I made it more PEP8 friendly. Also, you should be displaying h, l and s… not H, L and S since your comparator against a uses lowercase. Either that, or change the case of the input value. Also, use raw_input instead of regular input.

    As @Blorgbeard mentions, if you want the same random numbers chosen each time, then add this before you call choice

    import random 
    random.seed(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is a complete example. I want to forbid using A::set from objects casted
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
Here's my scenario: <!-- Normal Control --> <div class=required> <label for=address1>Address line 1</label> <input
Here is an example: I write html code inside of textarea, then I swap
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is a code snippet I was working with: int *a; int p =
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY

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.