0
Why else did not work
#جواب به توان n عدد مختلط (i) h = input() d = h % 4 if d == 0 : print ("1") elif d == 1 : print ("i") elif d == 2 : print ("-1") elif d == 3 : print ("-i") else : print ("undefined")
8 Answers
+ 2
When you input a word of character then int(h) will raise error.
If you put any valid number then d value can be 0,1,2,3 only. No other values possible so else part is no use..
You may trying to exception handling when input is not valid number?
Then try :
h = input()
try :
d = int(h) % 4
if d == 0 :
print ("1")
elif d == 1 :
print ("i")
elif d == 2 :
print ("-1")
elif d == 3 :
print ("-i")
except :
print ("undefined")
+ 7
AmIraN gh ,
we still lack a useful task description.
> can you please tell us what your code should achieve?
+ 2
input() accept as string format. Convert to needed type. Otherwise h%4 is error.
h = int( input() )
+ 1
You only need to handle any letter before entering the if else statments
try:
h = int(input())
except ValueError:
print("Undefined")
d = h % 4
if d == 0 :
print ("1")
elif d == 1 :
print ("i")
elif d == 2 :
print ("-1")
elif d == 3 :
print ("-i")
+ 1
Jayakrishna 🇮🇳 and Mohamed Youssef Belloui I'm sorry what about this coad
Why else did not work about words and sentences
h = input()
d = int(h) % 4
if d == 0 :
print ("1")
elif d == 1 :
print ("i")
elif d == 2 :
print ("-1")
elif d == 3 :
print ("-i")
else :
print ("undefined")
+ 1
Jayakrishna 🇮🇳 thank you so much
+ 1
Lothar In math there is a case about complex numbers.
So I create this coad to find the answer of complex numbers power
0
I want to print Undefined when the user prints word in the input