Python 我想使用我的原始输入使用我的函数
我有一个程序,我一直在工作,看看我是否可以使用我的函数的原始输入Python 我想使用我的原始输入使用我的函数,python,function,raw-input,Python,Function,Raw Input,我有一个程序,我一直在工作,看看我是否可以使用我的函数的原始输入 class object: # this shows that x is on top of y def on(self,x,y): self.x = x self.y = y x = 1 y = 0 if x > y: print True else: print Fal
class object:
# this shows that x is on top of y
def on(self,x,y):
self.x = x
self.y = y
x = 1
y = 0
if x > y:
print True
else:
print False
# this clears x making nothing be on top of x
def clear(self,x):
self.x = x
x = None
print(x)
# this shows that x is bigger than y
def heavy(self,x,y):
self.x = x
self.y = y
x = 1
y = 0
if x > y:
print True
else:
print False
input = raw_input("Enter an object: (Type stop to stop the loop): ") # raw input allows me to write string without the quotes
obj = ""
while input != ("stop"):
obj = obj + " " + input
input = raw_input("Enter an object: ")
print ("These are the objects: " + obj)
# this is a loop that allows the user to enter as many objects until they type stop
我希望当用户输入两个单词时,我可以使用我创建的函数。例如,如果我使用on()(第一个函数),它将显示(on)(word1,word2),如果我使用clear,它将显示(clear)(word1)清除第二个单词。我只是想知道我是否在正确的轨道上。希望解释得很好,谢谢
希望成为这个伟大社区的一员:)如果我理解你的要求,请看下面的内容 下面我有4个已定义的变量。其中3个将执行不同的任务。第4个用于确定要使用的变量。我希望这为您指明了正确的方向
def random_words(word,word2):
print (word +"\n"+"First"+"\n"+ word2)
# you can decide how to print each string given.
# This will allow you to place one on top of the other.
# the "\n" will print the following string on the next line.
def other_words(word,word2):
print (word +" Second "+ word2)
def more_words(word,word2):
print (word +" Third "+ word2)
def select_def(sdef,word,word2): # This variable will decide the others
if sdef == "1":
random_words(word,word2)
elif sdef == "2":
other_words(word,word2)
else:
more_words(word,word2)
var1= str(input("Enter a number -->"))
var2= str(input("Enter a Word -->"))
var3= str(input("Enter another -->"))
select_def(var1,var2,var3)
调用函数的示例
select_def("2","Makin","Bacon") #You can use something like this in an input function.
结果:
>>>
Makin Second Bacon
>>>
Makin
First
Bacon
第二个例子:
select_def("1","Makin","Bacon")
结果:
>>>
Makin Second Bacon
>>>
Makin
First
Bacon
欢迎使用Stack Overflow!现在还不清楚您在这里需要什么样的帮助/问题是什么。您可能会发现阅读和了解这一点很有用,因为它看起来并不特别枯燥。作为第一关改进,您可以通过“第一关”、“第二关”我只是展示了如何使用不同字符串的输入来选择不同的函数。这只是一个起点。概念证明。他们正试图使用用户的输入来选择他们所做的函数。公平地说,我在我的手机上,所以不能说得太多,但他们似乎已经有了实现这些功能的方法你可能是对的。我只学了大约2个半月的python和编程。我确信有更干净的方法来产生他们想要的结果。