[英]How do I use input from one function in a different function?
Can someone explain to me how I can use the input from one function in another?有人可以向我解释如何在另一个函数中使用来自一个函数的输入吗? I have seen different questions but it doesn't make any sense to me: What is the purpose of the return statement?
我见过不同的问题,但对我来说没有任何意义: return 语句的目的是什么?
I am trying to use the input here as the sides of a triangle.我试图将这里的输入用作三角形的边。 The next function should get that input and use it to get the perimeter.
下一个函数应该获取该输入并使用它来获取周长。 I want to be able to use those three sides later on in another function.
我希望稍后能够在另一个函数中使用这三个方面。 This is what I have:
这就是我所拥有的:
#Input Func. using map
def u_input_map():
print("Enter the length of all sides")
lengths = input("Please enter enter the length of all sides in this
format: a, b, c ").split(',')
sides = list(map(int, lengths))
print(sides[0],sides[1],sides[2])
return(sides)
u_input_map()
# Triangle Perimeter Func.
# P = a + b + c
def perim(u_input_map):
all_sides = (sides[0]+sides[1]+sides[2])
print(all_sides)
return sides
perim(u_input_map)
I just want someone to point me in the right direction.我只是希望有人指出我正确的方向。 I want to figure this out on my own so I don't need the code.
我想自己解决这个问题,所以我不需要代码。
#Input Func. using map.
def u_input_map():
print("Enter the length of all sides")
lengths = input("Please enter enter the length of all sides in this
format: a, b, c ").split(',')
sides = list(map(int, lengths))
print(sides[0],sides[1],sides[2])
return sides
# Triangle Perimeter Func.
# P = a + b + c
def perim(sides):
all_sides = (sides[0]+sides[1]+sides[2])
return all_sides
old_sides = u_input_map()
perimeter = perim(old_sides)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.