简体   繁体   English

如何在另一个函数中使用来自一个函数的输入?

[英]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.

相关问题 如何在另一个 function 的输入中使用? - How do I use in input from one function in another? 如何从一个函数中获取一个值并在另一个函数中使用它? - How do I take a value from one function and use it in another? 如何在同一类的另一个函数中使用一个函数中的一个对象 - How do I use one object from one function in another function in the same class 如何将输入变量从一个 function 传递到另一个,而无需多次请求输入? - How do I passing an input variable from one function to another without it asking for the input multiple times? 如何在另一个函数中使用一个函数收集的数据 - How do I use the data collected of one function in another function 如何将一个 function 的 output 用于另一个 function? - How do I use the output of one function for another function? 如何在python中的另一个函数中使用一个函数中的数据? - How do I use data from one function in another function in python? 如何在另一个 function 中使用来自一个 function 的本地定义变量? - How do I use a locally defined variable from one function in another function? 如何从一个 function 获取输入并使用它来制作协程? - How to take input from one function and use it to make a coroutine? 如何将变量从一个函数发送到另一个函数? - How do I send a variable from one function to another function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM