编程实现:编写函数实现输入英文星期几的第一个字母,用判断是星期几,如果第一个字母相同,则继续判断第二个字母,以此类推,要求函数能将判断结果输出
时间: 2024-05-12 17:14:51 浏览: 65
1.rar_数学计算_C/C++_
以下是 Python 代码实现:
```python
def get_weekday(letter):
letter = letter.lower()
if letter == 'm':
return 'Monday'
elif letter == 'w':
return 'Wednesday'
elif letter == 'f':
return 'Friday'
elif letter == 't':
second_letter = input("Enter second letter: ").lower()
if second_letter == 'u':
return 'Tuesday'
elif second_letter == 'h':
return 'Thursday'
else:
return 'Invalid input'
elif letter == 's':
second_letter = input("Enter second letter: ").lower()
if second_letter == 'a':
return 'Saturday'
elif second_letter == 'u':
return 'Sunday'
else:
return 'Invalid input'
else:
return 'Invalid input'
# 测试代码
letter = input("Enter the first letter: ")
weekday = get_weekday(letter)
print(weekday)
```
运行结果示例:
```
Enter the first letter: t
Enter second letter: u
Tuesday
```
阅读全文