A collection of exercises for Python beginners(Q2)
As a Python beginner, I’ve done a lot of practice. Most of these exercises are very interesting. In order for the other beginners to get to learn the basic usage of the language faster, I have compiled the results of my exercises for your reference. As I am a foreign student, this exercise is written in English. Most of the exercises come from 《C语言初学者趣味编程100例》(贾蓓/郭强/刘占敏). A small number of cases come from the Internet. If any case violates your rights, please tell me, and I will delete it as soon as possible.
Q2.Method of borrowing
Question:
Emma has 5 books to lend to Amy, Bob and Celina. If each person can only borrow one book at a time, then how many kinds of borrowing can there be?
Python Code:
a=0
for i in range(1,6):
for j in range(1,6):
for k in range(1,6):
if i!=j and j!=k and i!=k:
a=a+1
print('A:',i,'B:',j,'C:',k)
print('Total:',a)
Running Results:
A: 1 B: 2 C: 3
A: 1 B: 2 C: 4
A: 1 B: 2 C: 5
A: 1 B: 3 C: 2
A: 1 B: 3 C: 4
A: 1 B: 3 C: 5
A: 1 B: 4 C: 2
A: 1 B: 4 C: 3
A: 1 B: 4 C: 5
A: 1 B: 5 C: 2
A: 1 B: 5 C: 3
A: 1 B: 5 C: 4
A: 2 B: 1 C: 3
A: 2 B: 1 C: 4
A: 2 B: 1 C: 5
A: 2 B: 3 C: 1
A: 2 B: 3 C: 4
A: 2 B: 3 C: 5
A: 2 B: 4 C: 1
A: 2 B: 4 C: 3
A: 2 B: 4 C: 5
A: 2 B: 5 C: 1
A: 2 B: 5 C: 3
A: 2 B: 5 C: 4
A: 3 B: 1 C: 2
A: 3 B: 1 C: 4
A: 3 B: 1 C: 5
A: 3 B: 2 C: 1
A: 3 B: 2 C: 4
A: 3 B: 2 C: 5
A: 3 B: 4 C: 1
A: 3 B: 4 C: 2
A: 3 B: 4 C: 5
A: 3 B: 5 C: 1
A: 3 B: 5 C: 2
A: 3 B: 5 C: 4
A: 4 B: 1 C: 2
A: 4 B: 1 C: 3
A: 4 B: 1 C: 5
A: 4 B: 2 C: 1
A: 4 B: 2 C: 3
A: 4 B: 2 C: 5
A: 4 B: 3 C: 1
A: 4 B: 3 C: 2
A: 4 B: 3 C: 5
A: 4 B: 5 C: 1
A: 4 B: 5 C: 2
A: 4 B: 5 C: 3
A: 5 B: 1 C: 2
A: 5 B: 1 C: 3
A: 5 B: 1 C: 4
A: 5 B: 2 C: 1
A: 5 B: 2 C: 3
A: 5 B: 2 C: 4
A: 5 B: 3 C: 1
A: 5 B: 3 C: 2
A: 5 B: 3 C: 4
A: 5 B: 4 C: 1
A: 5 B: 4 C: 2
A: 5 B: 4 C: 3
Total: 60