Python Forum
Division calcuation with answers to 1decimal place.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Division calcuation with answers to 1decimal place.
#1
I'm trying to write a program that takes two random integers from 0-10 and divides them by each other and have the user enter the answer to one decimal place.

I keep on getting incorrect even though I think I'm trying in the correct answer.

The code is below. Please help.

import random

first = random.randint(0,10)
second = random.randint(0,10)

symbol = " / "
print(first, symbol, second, "=")

answer = first / second
answer = ("{:.1f}".format(answer)) # division answer to 1 decimal place

print(answer) # The print is for testing purposes.

user_answer = float(input("enter you answer to one decimal place"))
  # mark answer
if user_answer == answer:
    # correct
    print("Correct!")
else:
    # incorrect
    print("Incorrect!")
Reply


Messages In This Thread
Division calcuation with answers to 1decimal place. - by sik - Jul-14-2021, 03:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'answers 2' is not defined on line 27 0814uu 4 793 Sep-02-2023, 11:02 PM
Last Post: 0814uu
  place 2 windows exactly above each other janeik 3 985 Jul-23-2023, 03:12 AM
Last Post: deanhystad
  Division questions Dionysis 5 1,102 Feb-14-2023, 02:02 PM
Last Post: Dionysis
  Division by zero and value of argument Lawu 5 3,211 Jul-01-2022, 02:28 PM
Last Post: Lawu
  Floor division problem with plotting x-axis tick labels Mark17 5 2,164 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Cannot 'break' from a "for" loop in a right place tester_V 9 4,049 Feb-17-2021, 01:03 AM
Last Post: tester_V
  Cannot Assign right Answers To Shuffled Questions Boblows 6 2,814 Jan-22-2021, 09:41 AM
Last Post: buran
  Floor division return value Chirumer 8 3,877 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE
  Integer division plozaq 2 2,016 Sep-28-2020, 05:49 PM
Last Post: plozaq
  Overcoming ZeroDivisionError: division by zero Error dgrunwal 8 5,133 Jun-12-2020, 01:52 PM
Last Post: dgrunwal

Forum Jump:

User Panel Messages

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