简体   繁体   English

我正在尝试使用上层功能进行输入

[英]I am trying to use the upper function for the input

我正在尝试输入用户输入的大写字母,但仅使问题大写

name = input("Please enter your name ".upper())

You are uppercasing the prompt , the string value passed to input() . 您正在大写提示 ,将字符串值传递给input() You need to uppercase the result , the value returned by the function: 您需要将result (该函数返回的值)大写:

name = input("Please enter your name ").upper()

Note the placement of the closing parentheses there. 注意此处的右括号的位置。

You could separate out the input() call from the uppercasing: 您可以从大写字母中分离出input()调用:

name = input("Please enter your name ")
name = name.upper()

if that makes it clearer for you. 如果这样可以使您更清楚。

In essence, your attempt did this instead: 本质上,您的尝试是这样做的:

prompt = "Please enter your name "
prompt = prompt.upper()
name = input(prompt)

which is why you see PLEASE ENTER YOUR NAME on your screen when you run your code. 这就是为什么在运行代码时在屏幕上看到“ PLEASE ENTER YOUR NAME原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试制作 function 以在 python 中将字符串转为大写,但有法语字符的问题 - I am trying to make a function to turn a string upper case in python but have problenm with french characters 我可以使用函数 'count()' 来查找密码中的大写字母数量吗? (蟒蛇) - Am I able to use the function 'count()' to find the amount of upper cases in a password? (PYTHON) Python:我正在尝试使用另一个函数返回的函数 - Python: I am trying to use a function returned by another function 为什么我在 python 3 中出现“function upper(bytea)”错误? - Why am I getting 'function upper(bytea)' error in python 3? 我正在尝试显示使用输入 function 获得的字符串的索引值 - I am trying to display the index value of strings which I have obtained using the input function 我正在尝试将过滤器函数与嵌套列表一起使用,但无法使用过滤器函数存储内部列表的第0个元素 - I am trying to use filter function with a nested list but I am not able to store the 0'th element of the inner list by using the filter function 我正在尝试用python编写一个函数,该函数需要用户输入并将其存储在列表中 - I am trying to write a function in python that takes user input and stores it in a list python 基础知识 - 我正在尝试编写一个 function,它将一个字符串(一个月)作为输入并返回该月的天数 - python basics - I am trying to write a function which takes a string(a month) as an input and returns the amount of days in the month 尝试在不使用函数的情况下检查输入中是否有任何大写、小写、非字母字母,但代码不起作用 - Trying to check if there are any upper case, lowercase, non alphabetical letters in the input without the use of functions, but code not working 我正在尝试将类与字典一起使用python - I am trying to use classes with a dictionary with python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM