昨天和你们分享了81-90题,今天继续来刷最后的91-100题git
Please write a program which accepts a string from console and print it in reverse order.**Example:
If the following string is given as input to the program:*github
rise to vote sir
Then, the output of the program should be:
ris etov ot esir
s = input() s = ''.join(reversed(s)) print(s)
s=input() s = s[::-1] print(s)
Please write a program which accepts a string from console and print the characters that have even indexes.*Example:
If the following string is given as input to the program:*api
H1e2l3l4o5w6o7r8l9d
Then, the output of the program should be:
Helloworld
s=input() print(s[::2])
s = "H1e2l3l4o5w6o7r8l9d" s = [ v for (i,v) in enumerate(s) if i%2 ==0 ] print(''.join(s))
Please write a program which prints all permutations of [1,2,3]
import itertools result = list(itertools.permutations([1,2,3])) print(result)
*Write a program to solve a classic ancient Chinese puzzle:
We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have? * (鸡兔同笼)
def solve(numheads,numlegs): ns='No solutions!' for i in range(numheads+1): j=numheads-i if 2*i+4*j==numlegs: return i,j return ns,ns numheads=35 numlegs=94 solutions=solve(numheads,numlegs) print(solutions)
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.app
If the following string is given as input to the program:学习
5 2 3 6 6 5Then, the output of the program should be:ui
5
n = int(input()) arr = map(int, input().split()) arr = list(set(arr)) arr.sort() print(arr[-2])
n = int(input()) arr = map(int, input().split()) arr = list(set(arr)) print(sorted(arr)[-2])
*You are given a string S and width W.
Your task is to wrap the string into a paragraph of width.*spaIf the following string is given as input to the program:code
ABCDEFGHIJKLIMNOQRSTUVWXYZ 4Then, the output of the program should be:orm
ABCD EFGH IJKL IMNO QRST UVWX YZ
import textwrap def wrap(string, max_width): string = textwrap.wrap(string,max_width) string = "\n".join(string) return string if __name__ == '__main__': string, max_width = input(), int(input()) result = wrap(string, max_width) print(result)
import itertools as it def grouper(lst, n, fillvalue=None): iters = [iter(lst)] * n return it.zip_longest(*iters, fillvalue=fillvalue) # 默认就是None string, max_width = input(), int(input()) result = grouper(string, max_width) print(list(result))
You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)ip
Different sizes of alphabet rangoli are shown below:
#size 3 ----c---- --c-b-c-- c-b-a-b-c --c-b-c-- ----c---- #size 5 --------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e--------
import string def print_rangoli(size): n = size alph = string.ascii_lowercase width = 4 * n - 3 ans = [] for i in range(n): left = '-'.join(alph[n - i - 1:n]) mid = left[-1:0:-1] + left final = mid.center(width, '-') ans.append(final) if len(ans) > 1: for i in ans[n - 2::-1]: ans.append(i) ans = '\n'.join(ans) print(ans) if __name__ == '__main__': n = int(input()) print_rangoli(n)
You are given a date. Your task is to find what the day is on that date.
Input
A single line of input containing the space separated month, day and year, respectively, in MM DD YYYY format.
08 05 2015
Output
Output the correct day in capital letters.
WEDNESDAY
import calendar month, day, year = map(int, input().split()) dayId = calendar.weekday(year, month, day) print(calendar.day_name[dayId].upper())
import datetime month, day, year = map(int, input().split()) dayId = datetime.date(year, month, day) print(dayId.strftime("%A"))
Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either M or N but do not exist in both.
Input
The first line of input contains an integer, M.The second line contains M space-separated integers.The third line contains an integer, N.The fourth line contains N space-separated integers.
4 2 4 5 9 4 2 4 11 12
Output
Output the symmetric difference integers in ascending order, one per line.
5 9 11 12
if __name__ == '__main__': n = int(input()) set1 = set(map(int,input().split())) m = int(input()) set2 = set(map(int, input().split())) ans = list(set1 ^ set2) print(sorted(ans))
You are given words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.
If the following string is given as input to the program:
4 bcdef abcdefg bcde bcdefThen, the output of the program should be:
3 2 1 1
n = int(input()) word_list = [] word_dict = {} for i in range(n): word = input() if word not in word_dict: word_list.append(word) word_dict[word] = word_dict.get(word, 0) + 1 print(len(word_list)) for word in word_list: print(word_dict[word], end=' ')
这十道题的代码在个人github上,若是你们想看一下每道题的输出结果,能够点击如下连接下载:
个人运行环境Python 3.6+,若是你用的是Python 2.7版本,绝大多数不一样就体如今如下3点:
到今天为止,这套题就已经所有结束了,相信你们若是看了每一道题,仍是对技能提高有些许帮助的!
若是你有更好的Python学习资料,想要分享或者交流,欢迎给我留言哈!
独乐乐不如众乐乐,你们一块儿进步,谢谢!