I'm coding this for hours & can't make the value of the 5 random numbers round off to 2 decimal places like in the examples | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

I'm coding this for hours & can't make the value of the 5 random numbers round off to 2 decimal places like in the examples

Write a program that generates a 5 random decimal number between 1 and 100 with two decimal places of accuracy. Examples are 1.23, 3.45, 9.80, and 5.00. Compute the average of the numbers.  from random import randint ##variable name= randint(minimum,maximum) num1=randint(1,100) num2=randint(1,100) num3=randint(1,100) num4=randint(1,100) num5=randint(1,100) print("num1: ", round(num1,2), sep="") print("num2: ", round(num2,2), sep="") print("num3: ", round(num3,2), sep="") print("num4: ", round(num4,2), sep="") print("num5: ", round(num5,2), sep="") average=(num1+num2+num3+num4+num5)/5 print("average: ", average)

6th Feb 2023, 4:23 PM
Erika Abalora
6 ответов
+ 3
Erika Abalora `randint` returns a random integer. What you want is a float number. Try the `uniform` function, which returns a random float in the given range: from random import uniform num1=uniform(1,100) ...
6th Feb 2023, 4:43 PM
Mozzy
Mozzy - avatar
+ 1
Erika Abalora Meaning you are only allowed to use randint and nothing else?
6th Feb 2023, 4:55 PM
Mozzy
Mozzy - avatar
+ 1
You're welcome :)
6th Feb 2023, 4:58 PM
Mozzy
Mozzy - avatar
+ 1
How I use this app
8th Feb 2023, 2:42 PM
Priyam Ghosh
Priyam Ghosh - avatar
0
but we are still not on that part I'm afraid, it will be counted as we are still in the basics of randint
6th Feb 2023, 4:45 PM
Erika Abalora
0
it worked, thankyouuuuuuu
6th Feb 2023, 4:55 PM
Erika Abalora