Python基础练习题目

Python基础练习题目1

1.利用range函数生成10以内(不包含10)数字,并用for循环依次输出。

for i in range(1, 10):
    print(i)

2.有players = [‘charles’,‘martina’,‘michael’,'florence,‘eli’]列表,请将列表中元素的首字母大写后依次输出。

players = ['charles','martina','michael','florence','eli']
for item in players:
    print(item.capitalize())

3.有列表cars = [‘audi’, ‘bmw’, ‘subaru’, ‘toyota’]。遍历该列表,输出各个元素,要求将‘bmw’所有首字母大写。其余首字母大写。

cars = ['audi', 'bmw', 'subaru', 'toyota']
for item in cars:
    if item == 'bmw':
        print(item.upper())
    else:
        print(item.capitalize())

4.有available_toppings = [‘mushrooms’, ‘olives’, ‘green peppers’, ‘pepperoni’, ‘pineapple’, ‘extra cheese’] 与requested_toppings = [‘mushrooms’, ‘french fries’, ‘extra cheese’]两个列表,请判断requested_toppings中的元素是否在avaialbe_toppings列表中,如果存在,输出’yes’,否则输出’no’。

available_toppings = ['mushrooms', 'olives', 'green peppers', 'pepperoni', 'pineapple', 'extra cheese']
requested_toppings = ['mushrooms', 'french fries', 'extra cheese']
for item in requested_toppings:
    if item in available_toppings:
        print('yes')
    else:
        print('no')

5.在星际大战游戏中,外星飞机水平移动距离与其速度类型直接相关其中,'slow’类型,飞机x轴每秒移动1个距离,'medium’类型,飞机x轴每秒移动2个距离,'fast’类型,飞机x轴每秒移动3个距离。请计算飞机alien_0 = {‘x_position’:0,‘y_position’:25, ‘speed’:‘medium’}飞行3秒后的位置,并对其位置进行修改,并输出新的横纵坐标位置。

alien_0 = {
   'x_position':0,'y_position':25, 'speed':'medium'}
def check_x(alien_0):
    if alien_0['speed'] == 'slow':
        alien_0['x_position'] += 3
    elif alien_0[
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值