+ 2
Pls can someone help me with this code
When I do this.... For x in range(i): If i<=10 Print("Ra") x+=1 If i=10 It would print Ra 10 times but I thought 10 is not in the range 10 Pls I need the answer quickly thank you
15 odpowiedzi
+ 6
your mistakes :
#1) all kewords (hopefully) in python are lowercase ( change For to for, Print to print
#2) i is not defined anywhere so i assume line 2 is checking against x , and
#3) you want to print something in range 10 so line 1 -> range(10)
#4) what is line 5 doing ?
#5) colon ( : ) is missing in line 2
with that said finally code should be like this ?
for x in range(10):
if x<=10:
print("Ra")
x+=1
+ 2
Oyedeji Hiqmat
you're right . but 0 is included ... so thera 10 numbers in range(10) 0 through 9
try running this to get a hint , why.
print(list(range(10)))
also you can try printing x along "Ra" .
the best way to learn is try changing the code to see what is affected ...
+ 2
Oyedeji Hiqmat
Yes. In the code x += 1 is no effect statement. It is not needed there. (1) (edit)
And start loop when if x <= 10: so loop inside if block. Not if inside in for loop. (2)
(3) Better to use elif instead of all if blocks... Hoping, Is this what you looking.. !!?
+ 2
Which one from my 3 statements? All? Oyedeji Hiqmat
+ 2
When u put it as <= 10, it will also print 10.... It will not print 10 if i<10
+ 1
It was part of a code that why it looking like that
+ 1
Prashanth Kumar yh it something like that
+ 1
Can u explain why it printed 10 when 10 is not with the range 10
+ 1
Prashanth Kumar.....I tried it and it produced
[0,1,2,3,4,5,6,7,8,9] it and 10 isnt included
And if 10 is included
How come if we are doing a code like
for x in range(10):
print("a")
It would only print 9 as
+ 1
i=int(input())
if i<1:print("shh")
if i>10:print("High Five")
for x in range(i):
if i<=10:
print("Ra!")
x+=1
##########
This is the actual code
so if we assume the i to be 10
+ 1
Prashanth Kumar
from those practice codes....I think the x+=1 is not needed so can u explain
+ 1
Jayakrishna
Sorry I don't really understand u
+ 1
If i <= 10 ● change it to ● if i < 10 ● This will count from 0 - 9 witch means 10 times ● without the change it will printing 11 times
0
Ok