HELP!!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

HELP!!!!

So I'm making a Exponent calculator and if the exponent is greater than 1, I wrote: if int(ex) => 1:for i in range(int(ex)):num = num * 2 But when I run it, I get a syntax error right after "(int(ex)):" and I've tried everything! So someone help!

29th Oct 2017, 8:18 PM
Lux Official
Lux Official - avatar
7 Answers
+ 10
Check it out, man: https://code.sololearn.com/cbpR6osJwgf2/?ref=app Python is very strict about indentation. Whenever you make a logical block of code, even a one-line command after if or else, you have to make an indent.
29th Oct 2017, 8:34 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 9
You have to maintain proper and consistent indentation throughout your code. Also, your conditional statements are not correct (or at least overdone). Besides, the comparison operators are 'smaller than or equal to' and 'greater than or equal to' -- they should be '<=' and '>='. There is no '=>' operator.
29th Oct 2017, 8:26 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 8
Hmm... I'm afraid I'd have to see it written to get it. By the way, you realize your whole code could be written in one line? print(int(input())**int(input()))
29th Oct 2017, 8:57 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 8
That's not actually correct. First of all, you have to end the line after the colon and make proper indentation. Second of all, the second if statement does not have to be 'greater than or equal to' - you already checked for equality to 1 a verse before. Finally, num * 2 is multiplication not exponentiation. If you do it in this for loop, you will just multiply by 2 'ex' times. By the way, when asking for ex and num, you can do it like this: ex = int(input()) num = int(input()) Then they will already be of integer type so you can use them without having to cast the type each time.
29th Oct 2017, 9:26 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
@Kuba SiekierzyƄski So I flipped the operators around but now I'm getting another syntax error at the u in the second num.
29th Oct 2017, 8:33 PM
Lux Official
Lux Official - avatar
0
@Kuba SiekierzyƄski Great! Thanks! But I also wrote if ex would equal 0: if int(ex) == 1: num = num And at the end of that command as well as the other I needed help with, I put: print(int(num) So what I did to test it is put... 1 (num) 1 (ex) In the input box.(Note i did not put this parenthesis in) and I get 11.
29th Oct 2017, 8:50 PM
Lux Official
Lux Official - avatar
0
@Kuba SiekierzyƄski No prob. Here it is: #Step 1 num = input() ex = input() ################################### #Step 2 if int(ex) == 1: num = num if int(ex) >= 1: for i in range(int(ex)):num = num * 2 print(int(num))
29th Oct 2017, 8:59 PM
Lux Official
Lux Official - avatar