Python例题(01)

一、运行下列程序

# 1
x = 77
print('%c  %X'%(x+32,x+32))
# 结果: m  6D
# 2
x = 5935.1476
print('%5.3f\t%e\n%12.5f'%(x,x,x))
#结果: 
# 5935.148	5.935148e+03
#   5935.14760
# 3
x = 2.5
y = 4.7
a = 7
print(x+a%3*int(x+y)%2//4)
# 结果:2.5
# 4
a = 3
b = 4
c = 5
print(a or b+c and b-c)
print(a+b>c and b==c)
# 结果:
# 3
# False
# 1
# False

二、编写下列程序

1.键盘输入两个两位数,组成一个新的四位数,如:x=25,y=46,则z=4526

x = int(input('输入两位数的x:'))
y = int(input('输入两位数的y:'))
z = y//10*1000+x%10*100+x//10*10+y%10
print('z的值为:',z)
# 结果
# 输入两位数的x:25
# 输入两位数的y:46
# z的值为: 4526

2.(对一个整数中的各位数字求和)编写一个程序,读取0到1000之间的整数并计算它的各位之和,例如:一个整数是932,它的各位之和就是14.(用%来提取数字,使用//运算符来除掉被提取的数字。例如:932%10=2,932//10=93。)

i = int(input('输入一个数字:'))
m=i//100+i%100//10+i%10
if i in range(1000):
    print('各位相加之和为:',m)
else:
    print('输入数据有问题,请重新换个数字:')
# 结果:
# 输入一个数字:932
# 各位相加之和为: 14
# or
# 输入一个数字:9320
# 输入数据有问题,请重新换个数字:

三、绘制图形

1.

import turtle as a
a.pensize(7)
a.color('blue')
a.goto(0,0)
a.forward(200)
a.right(90)
a.forward(200)
a.right(90)
a.forward(200)
a.right(90)
a.forward(200)
a.right(90)
a.penup()
a.goto(0,-100)
a.pendown()
a.forward(200)
a.right(90)
a.penup()
a.goto(100,0)
a.pendown()
a.forward(200)
a.penup()
a.goto(100,-100)
a.done()

2.

import turtle as b
b.goto(0,0)
b.pensize(5)
b.color('green')
b.circle(-30)
b.penup()
b.goto(60,0)
b.pendown()
b.circle(-30)
b.penup()
b.goto(60,60)
b.pendown()
b.circle(-30)
b.penup()
b.goto(0,60)
b.pendown()
b.circle(-30)
b.done()

3.

import turtle as c
c.pensize(5)
c.color('red')
c.right(72)
c.forward(200)
c.right(144)
c.forward(200)
c.right(144)
c.forward(200)
c.right(144)
c.forward(200)
c.right(144)
c.forward(200)
c.done()

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雨天_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值