Processing user input in a python program

Brandon

I am making a program that gives the user a random integer from 1 to 10 as a diameter using a list and they have to calculate the circumference of a circle using Pi as 3. In my code when a user inputs a string instead of an integer, the program asks the user to input an integer instead. If the user then inputs a correct answer, the program says it is an incorrect answer. I need the program to say it is correct. Any chance I could get some help? here is my code:

import turtle
import random
turtle.speed("fastest")


pi = 3
minNumber = 4
maxNumber = 10
score = 0
listNmbers = []
a = [1,3,5,7,9]

red = random.random()
green = random.random()
blue = random.random()

num1 = random.choice(a)


def askCir(cirAnswer):
    try: 
        user = input("What is the circumference of a circle if the diameter is " + str(num1) + " and Pi is 3?")
        cirAnswer = int(user)   
    except:
        print("Please input a number only!")
        cirAnswer = 0;
        cirAanswer = askCir(cirAnswer)
    return cirAnswer
    cirAnswer = 0;
    cirAnswer = askCir(cirAnswer)



print("Welcome! What is your name??")
name = str(input())
print("Hello", name,"you need to calculate the circumference of a circle when given a diameter. To calculate the circumference, use the equasion; Pi x Diameter (Pi = 3")


def getNumbers():
    num = input("how many questions would you like to answer? (Pick between 5 and 10)")
    try:
        numbers = int(num)
    except:
        print("That is not a number!")
        return getNumbers()
    goodInput = minNumber < numbers < maxNumber

    if not goodInput:
        print ("That is not between 5 and 10. Please input an integer between 5 and 10.")
        return getNumbers()
    else:
        return numbers
numbers = getNumbers()    


for i in range(numbers):
    red = random.random()
    green = random.random()
    blue = random.random()
    turtle.color(red,green,blue)
    num1 = random.choice(a)
    correct = num1 * 3

    cirAnswer = 0;
    cirAnswer = askCir(cirAnswer)
    print(str(correct))

    if float (cirAnswer) == correct:
        print("That's Correct! Well Done")
        score = score + 1
    else:
        print("Sorry that is incorrect")

    for k in range(correct):
        turtle.color(red,green,blue)
        drawSquare()

    turtle.penup()
    turtle.forward(150)
Yuvika

It is not working because of a typo in your program.

cirAanswer = askCir(cirAnswer) needs to be

cirAnswer = askCir(cirAnswer)

Basically the new answer was being assigned to a new variable cirAanswer and 0 was always being returned

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Processing user input in simple Python program

From Dev

Ending a python program with user input

From Dev

Need Python to register user input in my program

From Dev

Processing user input in C

From Dev

Python: wait for user input, and if no input after 10 minutes, continue with program

From Dev

Python program to take user input and refresh console without "scrolling"

From Dev

Python program does not execute beyond first user input

From Dev

Python getting days of the month out of an input from a user in the program

From Dev

Python program assigning code to random integer, and checking with user input not functioning

From Dev

User input to repeat program in Java

From Dev

Java program not reading user input

From Dev

matrices program asking for user input

From Dev

Taking in a user input to load a program

From Dev

Modification of Bubblesort program with user input

From Dev

Input and Output program for python

From Dev

Python program not asking for input

From Dev

Allow code to stop processing and wait for user input

From Dev

Allow code to stop processing and wait for user input

From Dev

Communicate between a processing sketch and a python program?

From Dev

Triangle side sum program with input from user (Think Python exercise 5-4-2)

From Dev

Write a Python program that repeatedly asks the user to input coin values until the total amount matches a target value

From Dev

C program skipping over user input?

From Dev

Java simple program not allowing to take user input

From Dev

Testing program that runs with user input from the console

From Dev

Keep running program until user input exit

From Dev

How to make a powershell program restart on user input

From Dev

C Program file-io user input

From Dev

Using Classes and methods with user input for an interactive program

From Dev

Why does the program not get input from the user?

Related Related

  1. 1

    Processing user input in simple Python program

  2. 2

    Ending a python program with user input

  3. 3

    Need Python to register user input in my program

  4. 4

    Processing user input in C

  5. 5

    Python: wait for user input, and if no input after 10 minutes, continue with program

  6. 6

    Python program to take user input and refresh console without "scrolling"

  7. 7

    Python program does not execute beyond first user input

  8. 8

    Python getting days of the month out of an input from a user in the program

  9. 9

    Python program assigning code to random integer, and checking with user input not functioning

  10. 10

    User input to repeat program in Java

  11. 11

    Java program not reading user input

  12. 12

    matrices program asking for user input

  13. 13

    Taking in a user input to load a program

  14. 14

    Modification of Bubblesort program with user input

  15. 15

    Input and Output program for python

  16. 16

    Python program not asking for input

  17. 17

    Allow code to stop processing and wait for user input

  18. 18

    Allow code to stop processing and wait for user input

  19. 19

    Communicate between a processing sketch and a python program?

  20. 20

    Triangle side sum program with input from user (Think Python exercise 5-4-2)

  21. 21

    Write a Python program that repeatedly asks the user to input coin values until the total amount matches a target value

  22. 22

    C program skipping over user input?

  23. 23

    Java simple program not allowing to take user input

  24. 24

    Testing program that runs with user input from the console

  25. 25

    Keep running program until user input exit

  26. 26

    How to make a powershell program restart on user input

  27. 27

    C Program file-io user input

  28. 28

    Using Classes and methods with user input for an interactive program

  29. 29

    Why does the program not get input from the user?

HotTag

Archive