用Python语言设计程序,5道题,谢谢! 用Python语言编写简单程序,救救孩子吧!!谢谢

www.zhiqu.org     时间: 2024-05-31
第一题,用input()接受用户输入,int()把输入转换成整型,if... else语句判断条件。能被2整除的是偶数,否则奇数
代码:
n = int(input())
if n % 2 == 0:
..#前面的点表示缩进。
..print("是偶数")
else:
..print("是奇数")
第二题input()、int()和嵌套if语句
代码:
n = int(input())
if n % 100 != 0:
..if n % 4 == 0:
....print("是闰年")
..else:
....print("是平年")
elif n % 400 == 0:
..print("是闰年")
else:
..print("是平年")
第三题还是一样滴,用input(),int()和if...else语句
代码:
a = int(input())
b = int(input())
if a > b:
..print(a – b)
else:
..print(b – a)
第四题也是一样滴
代码:
m = int(input())
n = int(input())
if m < n:
..print(m, n)
else:
..print(n, m)
第五题 (*^▽^*)
代码:
a = int(input())
if a >=60:
..print("合格")
else:
..print("不合格")

基础题
不难 if 分支 判断

第三题 其实就是 求绝对值

哎 ....

用Python语言编写简单程序,谢谢~

大致这样

# -*- coding: UTF-8 -*-
#1.编写程序,输入3个数,计算a,b,c的和并输出。

a = input("请输入a")
b = input("请输入b")
c = input("请输入c")

sum = float(a)+float(b)+float(c)

print("a+b+c=", sum)

#2. 编写程序,输入三角形的两条直角边(实数),计算斜边长度并输出,保留2位小数。
A = float(input("请输入三角形直角边A"))
B = float(input("请输入三角形直角边B"))

C = (pow(A, 2)+pow(B, 2))**0.5
print("斜边C=", C)


#诸蔡牲# python编写1+(1+3)+(1+3+5)+……(1+3+5+……+n)和的程序 -
(19140881449): #!/usr/bin/python3 def fun(n): if n < 0 or n%2 == 0: raise Exception('参数必须是正奇数') sum = 0 for j in range(n//2+1): for i in range(1,(j+1)*2,2): sum += i return sum print(fun(7))原创代码,fun函数参数可换成其他正奇数,参数检测有错误抛异常,不懂之处追问.

#诸蔡牲# 这个题该怎么用Python编出来 -
(19140881449): import math print '%+9s %+9s %+9s %s'%('x','cos(x)','sin(x)','sqrt(cos^2(x)+sin^2(x)') for i in range(0,21): x = (i/21.0) * math.pi/2.0 c = math.cos(x) s = math.sin(x) q = math.sqrt(c**2+s**2) print '%9f %9f %9f %9f'%(x,c,s,q)

#诸蔡牲# 求一段Python编程语言 求设计一段Python编程语言,解答下列问题. 输入两个点,建立起直线 -
(19140881449): 回炉了一下几何,图形学用到 import math class Point: def __init__(self): self.x=0 self.y=0 def input(self,pname): self.x=int(input("Enter the x of point {0}: ".format(pname))) self.y=int(input("Enter the y of point {0}: ".format(pname))) a=Point() ...

#诸蔡牲# 有关Python 编程语言的 急!!!!! -
(19140881449): 第一题做了下.以前弄个就贴给你了 #!/bin/usr/python#-*-coding:GB2312-*-#filename:Fileproperties.py import os import time def Show_File_Properties(path): ''' Function_Name:Show_File_Properties(path) 显示文件的属性-包括路径、大小、创建...

#诸蔡牲# 用 PYTHON写FUNCTION -
(19140881449): >>> def s(M):... if M==1:... return 1... else:... return s(M-1)+1.0/M>>> import math>>> def Gauss(x,m=0,s=1):... return (1/(math.sqrt(2*math.pi)*s))*math.exp(-0.5*((x-m)/s)**2)... >>> li = [-5,-4,-3,-2,-1,0,1,2,3,4,5]>>> print map(Gauss,li) [1....

#诸蔡牲# 关于python语言的小程序题 求指点,谢谢了! -
(19140881449): import random a=[] i=random.randint(1,10) for j in range(1,i+1): x=random.randint(0,9) a.append(x) print a k=random.randint(1,10) b=[] for m in range(1,k+1): y=random.randint(0,9) b.append(y) print b c=list(set(a)&set(b)) print c d=list(set(a)|set(b)) print d

#诸蔡牲# Python实验题目,求助大佬 -
(19140881449): 以下是代码:all_tuple = [] sum_stu = int(input('请输入一共有多少个学生:')) while(sum_stu>0):a = input('请输入学生名字:') class1 = float(input('第一门课的成绩:')) class2 = float(input('第二门课的成绩:')) class3 = float(input('第三门课的成绩:')...

#诸蔡牲# 编程题5,帮忙做下,谢谢!急! -
(19140881449): int fun(char *ss, char c) { int ans=0;while (*ss){if (c==*ss) ans++;ss++;}return ans;}

#诸蔡牲# Python设计文本搜寻与分析小程序? -
(19140881449): 修正一下:import re allm = re.findall(r'(?).*\n.*', open('all.txt').read()) alll = [(s.split('\n')[0], s.split('\n')[1])for s in allm]#print 'alldict:' + str(alldict) partm = re.findall(r'(?).*\n.*', open('part.txt').read()) partl = [(s.split('\n')[0], s.split('\n')[1])for s in partm]#print '...

#诸蔡牲# python小白,请大神写一个小程序,最多5句话吧,谢谢 -
(19140881449): def f(): a=input('first number:') b=input('second number:') print(a+' + '+ b +' = ',int(a)+int(b)) f() first number:4 second number:54 + 5 = 9