python第七章程序练习题
时间: 2023-10-23 21:50:53 浏览: 81
好的,以下是Python第七章的程序练习题:
1. 编写一个程序,实现两个数的加减乘除运算,用户可以输入运算符号来选择不同的运算方式。
2. 编写一个程序,实现输入一个字符串后,将其中的所有数字提取出来,并计算它们的和。
3. 编写一个程序,实现将一个列表中的元素去重后输出。
4. 编写一个程序,实现将一个列表中的元素按照从大到小的顺序排列,并输出排列后的列表。
5. 编写一个程序,实现将一个字典中的键值对按照键的字母顺序排列,并输出排列后的字典。
6. 编写一个程序,实现输入一个字符串后,判断它是否为回文字符串。
7. 编写一个程序,实现输入一个字符串后,统计其中每个字符出现的次数,并输出统计结果。
8. 编写一个程序,实现输入一个列表和一个数字,将这个数字插入到列表中的正确位置,并输出插入后的列表。
9. 编写一个程序,实现输入一个字符串和一个子字符串,统计子字符串在字符串中出现的次数,并输出统计结果。
10. 编写一个程序,实现输入一个字符串和一个正整数n,将字符串分成长度为n的子字符串,并输出这些子字符串。如果字符串长度不能被n整除,则将剩余的字符单独作为一个子字符串输出。
希望这些题目能够帮助你提高Python编程技能。
相关问题
python每日一练练习题
很高兴为您解答。Python每日一练是一种提高编程技能的好方法,它可以帮助您保持对Python的熟练掌握,并提高您的编程能力。以下是一些Python每日一练练习题的例子:
1. 编写一个程序,将一个列表中的元素去重。
2. 编写一个程序,找出一个字符串中出现次数最多的字符。
3. 编写一个程序,将一个字符串中的单词按照字母顺序排序。
4. 编写一个程序,计算一个列表中所有元素的平均值。
5. 编写一个程序,将一个列表中的元素按照奇偶性分成两个列表。
6. 编写一个程序,找出一个列表中第二大的元素。
7. 编写一个程序,将一个字符串中的元音字母替换成指定的字符。
8. 编写一个程序,将一个列表中的元素按照出现次数从高到低排序。
9. 编写一个程序,将一个字符串中的单词首字母大写。
10. 编写一个程序,找出一个列表中最大的连续子序列的和。
python if else练习题
好的,以下是 Python if else 练习题:
1. 编写一个程序,判断一个数是否为偶数。
```python
num = int(input("请输入一个整数:"))
if num % 2 == 0:
print(num, "是偶数")
else:
print(num, "不是偶数")
```
2. 编写一个程序,判断一个年份是否为闰年。
```python
year = int(input("请输入一个年份:"))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(year, "是闰年")
else:
print(year, "不是闰年")
```
3. 编写一个程序,输入三个数,输出其中最大的数。
```python
a = float(input("请输入第一个数:"))
b = float(input("请输入第二个数:"))
c = float(input("请输入第三个数:"))
if a >= b and a >= c:
print(a, "是最大的数")
elif b >= a and b >= c:
print(b, "是最大的数")
else:
print(c, "是最大的数")
```
4. 编写一个程序,输入三个数,输出其中最小的数。
```python
a = float(input("请输入第一个数:"))
b = float(input("请输入第二个数:"))
c = float(input("请输入第三个数:"))
if a <= b and a <= c:
print(a, "是最小的数")
elif b <= a and b <= c:
print(b, "是最小的数")
else:
print(c, "是最小的数")
```
5. 编写一个程序,输入一个字符,判断它是大写字母、小写字母还是数字。
```python
ch = input("请输入一个字符:")
if ch.isupper():
print(ch, "是大写字母")
elif ch.islower():
print(ch, "是小写字母")
elif ch.isdigit():
print(ch, "是数字")
else:
print(ch, "不是大写字母、小写字母或数字")
```
6. 编写一个程序,输入一个年龄,判断它是否为儿童(0-12岁)、青少年(13-18岁)或成年人(19岁及以上)。
```python
age = int(input("请输入一个年龄:"))
if age < 0:
print("输入有误")
elif age <= 12:
print("儿童")
elif age <= 18:
print("青少年")
else:
print("成年人")
```
7. 编写一个程序,输入一个月份,输出该月份的天数。
```python
month = int(input("请输入一个月份:"))
if month in [1, 3, 5, 7, 8, 10, 12]:
print(month, "月有31天")
elif month in [4, 6, 9, 11]:
print(month, "月有30天")
elif month == 2:
year = int(input("请输入一个年份:"))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(month, "月有29天")
else:
print(month, "月有28天")
else:
print("输入有误")
```