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

  • SEARCH
  • Home
  • 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 8854513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:53:55+00:00 2026-06-14T13:53:55+00:00

I coded a little math quiz that I need to insert in a loop

  • 0

I coded a little math quiz that I need to insert in a loop (while..)
to make it iterates a new time a user wants to.
Especially, how do I make it generate ”new random numbers” each time it iterates.
I know I can insert a control variable such as keep_going = y
to let user decide whether to continue or not.

Please see codes below, and thanks for the help!

import random

first_num = random.randint(1,500)
second_num = random.randint(1,500)

print (first_num)
print (second_num)

answer = int(input('Entrer la somme des deux nombres: '))

if answer == first_num + second_num:
    print("It's correct!")

else:
    print("It's wrong!")
  • 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-14T13:53:56+00:00Added an answer on June 14, 2026 at 1:53 pm

    What you need is a while loop. This one will loop forever until the user gets the question right, but you could put any condition after while that might eventually be false.

    Then I use raw_input() to have the user determine whether or not to continue. This is one of many ways to accomplish what you’re going for.

    import random
    
    while True:
    
        first_num = random.randint(1,500)
        second_num = random.randint(1,500)
    
        print (first_num)
        print (second_num)
    
        answer = int(input('Entrer la somme des deux nombres: '))
    
        if answer == first_num + second_num:
            print("It's correct!")
            break
        else:
            print("It's wrong!")
            tryAgain = raw_input('Try again? [(y)/n] ')
            if tryAgain.lower() == 'n':
                break
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple little dialog that lets user setup a time block. The
I'm trying to make a little dynamic quote rotator that overlays text on an
For my little app I need to do some very simple math... But for
I've put together a little app using Kendo UI that stores user inputs in
I have probably a simple math problem that I'm having surprisingly hard time figuring
I was for quite some time under the impression that a for loop could
I am a little confused about object assignment and pointers in Ruby, and coded
Code This is my little game of pig. I only got it coded for
found this little code snippet that seems to do what i want, but im
There is very little code out there that is in VB, and i'm getting

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.