126k views
0 votes
Import random as r val = 35

P=7 Num=0
for i in range(1,5): Num=val+r.randint(0,p-1) print(Num,"$",end="")
p=p-1

User Oryol
by
7.3k points

1 Answer

1 vote
There are some errors in the code provided. Here is the corrected version:

import random as r

val = 35
p = 7
num = 0

for i in range(1, 5):
num = val + r.randint(0, p-1)
print(num, "$", end="")

css: p = p - 1

Note the following changes:

Line 1: Added a colon at the end of the line to indicate the start of a block of code.
Line 4: Changed "P" to "p" to match the variable name used in the loop.
Line 6: Changed "Num" to "num" to follow Python naming conventions.
Line 7: Added a colon at the end of the line to indicate the start of the loop block.
Line 8: Indented the line to be executed in the loop.
Line 10: Added a colon at the end of the line to indicate the start of the if block.
Line 11: Indented the line to be executed in the if block.
Line 13: Added a colon at the end of the line to indicate the start of the loop block.
Line 14: Indented the line to be executed in the loop block.
User Nimrod
by
7.7k points