+ 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

5th Sep 2022, 8:56 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
16 Answers
+ 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
5th Sep 2022, 9:01 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 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 ...
5th Sep 2022, 9:37 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 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.. !!?
5th Sep 2022, 10:19 AM
Jayakrishna 🇮🇳
+ 2
Which one from my 3 statements? All? Oyedeji Hiqmat
5th Sep 2022, 3:26 PM
Jayakrishna 🇮🇳
+ 2
When u put it as <= 10, it will also print 10.... It will not print 10 if i<10
6th Sep 2022, 12:11 PM
Onyebuchi David
+ 1
It was part of a code that why it looking like that
5th Sep 2022, 9:31 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 1
Prashanth Kumar yh it something like that
5th Sep 2022, 9:31 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 1
Can u explain why it printed 10 when 10 is not with the range 10
5th Sep 2022, 9:32 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 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
5th Sep 2022, 9:51 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 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
5th Sep 2022, 9:56 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 1
Prashanth Kumar from those practice codes....I think the x+=1 is not needed so can u explain
5th Sep 2022, 9:58 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 1
Jayakrishna Sorry I don't really understand u
5th Sep 2022, 2:20 PM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 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
6th Sep 2022, 9:56 PM
Omar Kaddoura
Omar Kaddoura - avatar
6th Sep 2022, 7:27 PM
Reza Eghbal
Reza Eghbal - avatar
0
Ok
6th Sep 2022, 9:05 PM
Shaafici Cismaan
Shaafici Cismaan - avatar