Chapter 1-2 Input three numbers from the keyboard into a, b, c, and output according to the formula value

topic description

insert image description here

answer

When I saw this question, I didn't even think about it. I thought it was very simple, so I just wrote

a = int(input())
b = int(input())
c = int(input())
print(b*b-4*a*c)

Then, I was severely slapped in the face.
insert image description here
Then, I found out that I still haven't fully grasped how to use the input function. In the title, it said "enter three values ​​​​in one line ", highlight the key, in one line! ! !
insert image description here
Obviously, this way, the wrapping output is correct

input().split

The input() function receives multiple user inputs and needs to be used in conjunction with split()

name, number, age = input('请输入姓名、号码和年龄:').split()
print(name, number, age)

insert image description here

String splitting function str.split()

Function prototype:
str.split(str="", num=string.count(str))

information = "lmy/19/2020/female"
gap = information.split('/', 3)
print(gap)

output :
**Lift chestnut:**

correct answer

a, b, c = input().split()
a, b, c = eval(a), eval(b), eval(c)
print(b*b-4*a*c)

Guess you like

Origin blog.csdn.net/qq_52109814/article/details/121874054