【Python Practice】Day 1- Question 1-3

'''
@Author: your name
@Date: 2020-07-05 22:55:33
@LastEditTime: 2020-07-05 23:43:41
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \vscode_py\day1.py
'''

# Question 1:
# Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, 
# between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line.
def Question1():
    for i in range(2000,3201):
        if i % 5 !=0 & i%7==0:
            print(i,end=",")   # end=','意思是末尾不换行,加逗号

# Question2:
# Write a program which can compute the factorial of a given numbers.
# The results should be printed in a comma-separated sequence on a single line.
# Suppose the following input is supplied to the program: 8 Then, the output should be:40320
def Question2():
    n=int(input())
    fact=1
    # i=1
    # while i<=n:
    #     fact=fact*i
    #     i=i=1
    for i in range(1,n+1):
        fact=fact*i

        
    print(fact)

def lamQ2(x):
    return 1 if x<=1 else  x*lamQ2(x-1)

# #Question 3:
# With a given integral number n, write a program to generate a dictionary that contains (i, i x i) 
# such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
# Suppose the following input is supplied to the program: 8
def Question3():
    n=int(input())
    dic={}
    for i in range(1,n+1):
        dic[i]=i*i
    print(dic)

# Using dictionary comprehension
def Q3():
    n=int(input())
    print({i:i*i for i in range(1,n+1)})

if __name__ == "__main__":
    # Question1()

    # Question2()
    # x=int(input())
    # print(lamQ2(x))

    # Question3()
    Q3()


github:
https://github.com/darkprinx/100-plus-Python-programming-exercises-extended

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值