github展示python100题
链接如下:
https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises.txt
以下为博主翻译后题目及解答,答案代码分为两个,第一条为博主个人解答(Python3),第二条为题目所提供答案(Python2)
………………………………………………………………………………
题目1-20链接:https://blog.csdn.net/weixin_41744624/article/details/103426225
本部分为题目21-40,等级难度1-3不定顺序(建议倒序食用);
题目41-60链接:https://blog.csdn.net/weixin_41744624/article/details/103575741;
题目61-80链接:
https://blog.csdn.net/weixin_41744624/article/details/103607992
题目81-98链接:https://blog.csdn.net/weixin_41744624/article/details/103646520
经检测题库去除重复只有98题啦(欢迎评论添加好题目)~
………………………………………………………………………………
21、问题:
机器人从原点(0,0)开始在平面内移动。机器人可以向上、下、左、右移动,只要给定步数。机器人运动轨迹如下:
UP 5
DOWN 3
LEFT 3
RIGHT 2
¡
方向后面的数字是步数。请写一个程序,计算出一系列运动和原点后距离当前位置的距离。如果距离是浮点数,则只打印最接近的整数。
例子:
如果将下列元组作为程序的输入:
UP 5
DOWN 3
LEFT 3
RIGHT 2
¡
那么,程序的输出应该是:
2
ls = []
while True:
n=input("please input:")
if not n:
break
ls.append(tuple(n.split(' ')))
x=0
y=0
for j in ls:
i = list(j)
if i[0] == "UP":
y +=int(i[1])
elif i[0] == "DOWN":
y +=-int(i[1])
elif i[0] == "LEFT":
x +=-int(i[1])
elif i[0] == "RIGHT":
x +=int(i[1])
else:
print ("wrong input!")
z=round((x**2+y**2)**1/2,0)
print (z)
import math
pos = [0,0]
while True:
s = raw_input()
if not s:
break
movement = s.split(" ")
direction = movement[0]
steps = int(movement[1])
if direction=="UP":
pos[0]+=steps
elif direction=="DOWN":
pos[0]-=steps
elif direction=="LEFT":
pos[1]-=steps
elif direction=="RIGHT":
pos[1]+=steps
else:
pass
print int(round(math.sqrt(pos[1]**2+pos[0]**2)))
22、问题:
写一个程序从输入中计算单词的频率。输出应该在按字母数字顺序对键排序后输出。
假设向程序提供了以下输入:
New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.
那么,输出应该是:
2:2
3.:1
3?:1
New:1
Python:5
Read:1
and:1
between:1
choosing:1
or:2
to:1
ls = input ("please input:").split()
digit = []
digitchar = []
upper = []
lower = []
for i in ls:
if i.isalpha():
if i.islower():
lower.append(i)
else