python的几个小程序,还是作业(笑)

python版本:3.8.5 64-bit

IDE:VScode(别和我说vscode不算IDE)
这次已经懒得抄题了(略略略)

a=3
s=0
while True:
    n=int(input("请输入猜的数字:"))
    if n<a:
        print("遗憾,太小了")
        s=s+1
    elif n>a:
        print("遗憾,太大了")
        s=s+1
    elif n==a:
        s=s+1
        print("预测{}次,你猜中了".format(s))
        brea
str1=input("请输入字符:")
litter=0
number=0
space=0
other=0
for s in str1:
    if (s>='a' and s<='z') or (s>='A' and s<='Z'):
        litter=litter+1
    elif s in '0123456789':
        number=number+1
    elif s==' ':
        space=space+1
    else:
        other=other+1
print("共有{}个英文字符,{}个数字,{}个空格,{}个其他字符".format(litter,number,space,other))
def gys(x,y):
    m=max(x,y)
    n=min(x,y)
    while m%n:
        m,n=n,m%n
    return n
def gbs(x,y):
    gys0=gys(x,y)
    n=x*y/gys0
    return n
a=eval(input('请输入第一个数:'))
b=eval(input('请输入第二个数:'))
gys1=gys(a,b)
gbs1=gbs(a,b)
print("最大公约数为{},最小公倍数为{}".format(gys1,gbs1))
from random import*
a=randint(0,100)
s=0
while True:
    n=int(input("请输入猜的数字:"))
    if n<a:
        print("遗憾,太小了")
        s=s+1
    elif n>a:
        print("遗憾,太大了")
        s=s+1
    elif n==a:
        s=s+1
        print("预测{}次,你猜中了".format(s))
        break
def isOdd(num):
    if num % 2 != 0:
        return True
    else:
        return False

s = eval(input('请输入一个整数:'))
a = isOdd(s)
print(a)
def isNum(num):
    try:        
        n=type(eval(num))
        if n==type(1):
            return True
        elif n==type(1.0):
            return True
        elif n==type(1+1j):
            return True       
    except:
        return False

n = input("请输入一个字符串:")
a = isNum(n)
print(a)
def multi(s):
    m = 1
    for i in s:
        m = m * int(i)
    return m

n = input("请输入若干整数:").split()
a = multi(n)
print(a)
def isPrime(num):   
    try:
        num = eval(num)
        if type(num) == type(1):
            if num<=1:
                return False
            elif num==2:
                return True
            else:
                for i in range(2,num+1):
                    if n% i == 0:
                        return False
                    else:
                        return True                     
        else:
                raise ValueError
    except ValueError:
        return "输入有误!请输入整数!"
    except:
        return "输入有误!请输入整数!"

n = input("请输入一个整数:")
a = isPrime(n)
print(a)
最后修改:2020 年 11 月 01 日 10 : 14 AM
如果觉得我的文章对你有用,请随意赞赏