我正在尝试编写一个程序,要求用户以mm/dd/yyyy格式输入日期并进行转换.因此,如果用户输入01/01/2009,程序应显示2009年1月1日.这是我的程序到目前为止.我设法转换月份,但其他元素有一个括号围绕它们,所以它显示1月[01] [2009].
date=input('Enter a date(mm/dd/yyy)')
replace=date.replace('/',' ')
convert=replace.split()
day=convert[1:2]
year=convert[2:4]
for ch in convert:
if ch[:2]=='01':
print('January ',day,year )
Run Code Online (Sandbox Code Playgroud)
先感谢您!
我正在尝试编写一个程序,将每个句子的第一个字母大写.这是我到目前为止所做的,但我无法弄清楚如何在句子之间添加句点.例如,如果我输入:你好.再见,输出是Hello Goodbye,期间已经消失.
string=input('Enter a sentence/sentences please:')
sentence=string.split('.')
for i in sentence:
print(i.capitalize(),end='')
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,要求用户输入两种颜色,然后显示结果颜色.这是我到目前为止:
#Define function that prompts user to enter data
def ask():
color1=input('Enter name of first primary color:')
color2=input('Enter name of second primary color:')
mixColors(color1,color2)
#Write function that displays the different color combinations
def mixColors(color1,color2):
if color1==red and color2==blue:
print('Mixing red and blue, you get purple.')
elif color1==blue and color2==red:
print('Mixing blue andred, you get purple.')
elif color1==red and color2==yellow:
print('Mixing red and yellow, you get orange.')
elif color1==yellow and color2==red:
print('Mixing yellow and red, you get orange.')
elif color1==blue and …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个显示员工身份,工作时间,工资和工资的程序.
该计划的第二部分要求用户输入员工的ID,以便显示他们的工资.
我的程序的第一部分工作正常,直到pay=input().当我尝试使用第二部分运行它时,它表示存在语法错误.
这是我的计划:
employeeId=[56588,45201,78951,87775,84512,13028,75804]
hours=[40,41,42,43,44,45,46]
payrate=[13.60,13.50,13.40,13.30,13.20,13.10,13.00]
wages=[544.00,553.50,562.80,571.90,580.80,589.50,598.00]
print('employeeId\thours\t\tpayRate\t\twages')
print(employeeId[0],'\t\t',hours[0],'\t\t',payrate[0],'\t\t',wages[0])
print(employeeId[1],'\t\t', hours[1],'\t\t',payrate[1],'\t\t',wages[1])
print(employeeId[2],'\t\t',hours[2],'\t\t',payrate[2],'\t\t',wages[2])
print(employeeId[3],'\t\t',hours[3],'\t\t',payrate[3],'\t\t',wages[3])
print(employeeId[4],'\t\t',hours[4],'\t\t',payrate[4],'\t\t',wages[4])
print(employeeId[5],'\t\t',hours[5],'\t\t',payrate[5],'\t\t',wages[5])
print(employeeId[6],'\t\t',hours[6],'\t\t',payrate[6],'\t\t',wages[6])
pay=input("Would you like to a see a specific employee's gross pay? Y/N:")
if pay=='Y'or pay=='y':
ID=input('enter employee Id:')
if ID=='56588':
print(ID': $',wages[0])
elif ID=='45201':
print(ID': $',wages[1])
elif ID=='78951':
print(ID': $',wages[2])
elif ID=='87775':
print(ID': $',wages[3])
elif ID=='84512':
print(ID': $',wages[4])
elif ID=='13028':
print(ID': $',wages[5])
elif ID=='75804':
print(ID': $',wages[6])
else:
print(' ')
Run Code Online (Sandbox Code Playgroud)
我看到以下语法错误:
File "code.py", line 19
print(ID': $',wages[0])
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)