How to get the input in following code in straight line like. 1 25 + 5 2 30 please tell how to get output in only twolin | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How to get the input in following code in straight line like. 1 25 + 5 2 30 please tell how to get output in only twolin

A = int(input()) B= str(input()) C= int(input()) if B == "x" : print(A*C) elif B == "+" : print(A+C) elif B == "-" : print(A-C) elif B == "/" : print(A/C) else : print("Error") #input A is 25 and input C is 5 output:- 25 / 5 5.0

21st Jan 2021, 4:42 AM
Tanishq Kamble
Tanishq Kamble - avatar
2 ответов
+ 3
I'll just explain what ChaoticDawg did. A, B, C = input().split() - - string.split() - - is a string method that converts string into list and split by whitespace by default (you can split the string whatever character you want) For example: "Hello World".split() >> [ "Hello", "World" ] - - - - - - - - - - - - - - - - So for example the input is 1 + 2: A, B, C = [ "1", "+", "2"] Since there are three variables and three elements in the list, we can "Unpack the values". A <--- "1" B <--- "+" C <--- "2"
21st Jan 2021, 6:51 AM
noteve
noteve - avatar
+ 2
A, B, C = input().split() A = int(A) C = int(C)
21st Jan 2021, 5:02 AM
ChaoticDawg
ChaoticDawg - avatar