1 min read

three missions

恭喜你,获得了第一条秘密信息! print(“No, a time bomb is about to explode!”)

2.请编写一个程序,算出前十五个斐波那契数。

fibonacci = []
fibonacci.append(1)
fibonacci.append(1) 
fibonacci_number = 15

for i in range(2,fibonacci_number):
    fibonacci.append(fibonacci[i-1] + fibonacci[i-2])
    
print(fibonacci)
## [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]

3.编写一个程序,建立一个列表,找出其中最大的一个数,并输出。

rand_numbers = [3,7,5,4,6,9,2]
max_number = rand_numbers[0]
for i in range(1,len(rand_numbers)):
    if rand_numbers[i] > max_number :
        max_number = rand_numbers[i]
    
print(max_number)
## 9

4.建立一个模块,里面要有个函数,可以算出被除数和除数的余数。编写一个程序,建立一个变量(里面是数字),判断它是奇数还是偶数(要用到这个模块)。

由于在R中调用python模块,有些技术问题。因此直接定义remainder函数,算出被除数和除数的余数。

def remainder(dividend,divisor):
    return(dividend % divisor)
    
number = 11
if remainder(number,2) == 0 :
    print("This is an odd number")
else:
    print("This is an even number")
## This is an even number