【问题标题】:failing using def and input together一起使用 def 和 input 失败
【发布时间】:2020-03-28 14:34:36
【问题描述】:

我是编程新手,并尝试通过 edx/microsoft 学习。

我在这个任务上失败了,我不明白。

定义yell_this()并使用可变参数调用

define variable   words_to_yell   as a string gathered from user  input()
Call  yell_this()  with   words_to_yell  as argument
get user input() for the string words_to_yell

我在 linux 上的 azure jupyter notebook 上使用 python 3

【问题讨论】:

  • 如果您指出您正在学习的资源,那将非常有帮助。一个链接会很棒!

标签: python python-3.x function input


【解决方案1】:

我会尽量回答这个问题的最佳理解

第 1 步。

将变量 words_to_yell 定义为从用户 input() 收集的字符串

在python中你可以这样定义一个变量:

words_to_yell = input('Please provide a word to yell: ')

这将定义一个变量,其中包含用户传入的任何内容

第 2 步。

以 words_to_yell 作为参数调用yell_this() 假设你定义了这个函数,你可以这样调用它

yell_this(words_to_yell)

【讨论】:

  • 谢谢。我已经解决了我之前没有定义 words_to_yell 的问题!
【解决方案2】:

#定义函数并要求用户输入

def words_to_yell():
    words_to_yell = input("Please type words to yell:")
    print(words_to_yell.upper() + "!!!")

#这样调用函数:

words_to_yell()

【讨论】:

    猜你喜欢
    • 2019-07-30
    • 2013-07-07
    • 2017-08-05
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2018-06-07
    相关资源
    最近更新 更多