- 1

what am I doing wrong in writing this python program?

t=int(input()) while(t>0): if(t>=1 and t<=200): h=int(input()) if(h>=1 and h<=168): if(h<=0): amt=0 elif(h>0 and h-10<=0): amt=30 else: amt=30+(5*(h-10)) print(amt) t=t-1 Q: A company XYZ Pvt Ltd, handles the parking of two wheelers at New Delhi railway station. They charge Rs 30 for the 10 hours and after those 5 rupees per hour. Help the company to make a bill system for H hours. Input Format First line of input contains a single integer T denoting the number of test cases. The only line of each test case contains an integer H denoting hour. Constraints 1<=T<=200 1<=H<=168 Output Format For each test case, print the Amount.

29th Aug 2022, 5:05 PM
ss7
4 Answers
+ 3
t=int(input()) amt = 0 while(t>0): if(t>=1 and t<=200): h=int(input()) if(h>=1 and h<=168): if(h<=0): amt=0 elif(h>0 and h-10<=0): amt=30 else: amt = 30 + 5*(h-10) print(amt) t=t-1
29th Aug 2022, 5:32 PM
JaScript
JaScript - avatar
+ 2
While loops need an exit case. The line: while(t > 0): Has an exit condition. That's when t == 0. But inside your loop I see no decrement of variable t. Meaning the loop will run forever.
29th Aug 2022, 5:18 PM
Slick
Slick - avatar
0
Saurabh Singh You declared amt inside if - else blocks. Outside of the blocks it is not exists. So declare in the block in which you are using to print or globally.
29th Aug 2022, 6:05 PM
Jayakrishna 🇼🇳
0
Given a positive integer n. Find whether a number is amazing or not. Print True if number is amazing else False. An amazing number is a natural number that is a product of two prime numbers. Input Format The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows, a single line of the input containing a positive integer N. Sample Input: 2 6 8 Constraints 1<=T<=100 1<=N<=100000 Output Format Print 'True' if it is amazing, otherwise print 'False Sample Output: True False
30th Aug 2022, 3:10 PM
Roopam Roy
Roopam Roy - avatar