python编程师圣诞树代码
@贡钥5781:python编程.在冬天一个单位打折,买一件商品打9折,两件8折3件7折,4件6折,写一个程序可以 -
郜狄17373742694…… #首先设置未知数 amount = 0 total_cost = 0 money_saved = 0 #设置输入 price = input (“输入价格”:) while price > 0: total_cost = total_cost + price amount +=1 if amount < 4: total_off = total_cost * (1- amount/10.00) #如果有变量 else: total_off =...
@贡钥5781:用python编程求多项式sn=1 - 3+5 - 7+9 - 11+……的前100项和 -
郜狄17373742694…… 见下在的代码 1 2 3 4 5 6 7 he =0 forn inrange(0,100): if(n %2==0): he +=2*n +1 else: he -=2*n +1 print(he)
@贡钥5781:Print the first non - digit in string s. (Python编程) -
郜狄17373742694…… def non_digits(s): for a in s: if not a.isdigit(): print a return
@贡钥5781:Python编程:输入三角形的边a, b, c,求夹角C -
郜狄17373742694…… 我刚做完这题.我的答案: import math a = float(raw_input()) b = float(raw_input()) c = float(raw_input()) degree = math.degrees(math.acos((a**2 + b**2 - c**2) / (2 * a * b))) print '{0:.{1}f}'.format(degree, 1)OJ测试通过.
@贡钥5781:python编程求100 - 1000范围内被9除余7、被5除3的最小两个整数? -
郜狄17373742694…… #求100-1000范围内被9除余7、被5除3的最小两个整数 for i in range(100,1000): if i%9==7: print('{}除以9余7'.format(i)) break #跳出循环 for j in range(100,1000): if j%5==3: print('{}除以5余3'.format(j)) break#跳出循环
@贡钥5781:用python编写程序 -
郜狄17373742694…… s=read("字符串") str=read("子字符串:") print(s.replace(str,' '))
@贡钥5781:如何运行Python程序 -
郜狄17373742694…… 1. 使用Python自带的IDLE 在开始-->程序-->Python2.5(视你安装的版本而不同)中找到IDLE(Python GUI),点击后弹出如下窗体:在>>>提示符后输入代码,回车,就可以执行此代码.IDLE支持语法高亮,支持自动缩进,支持方法提示,不过提...
@贡钥5781:Python编程#输出n以内的所有质数. -
郜狄17373742694…… 质数又称素数.指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数. 一般正常人的解法是两次循环,假设求小于N的所有素数.一次用N-1之间的所有数去除,如果能被整除这个数肯定不是素数.否则是素数.
郜狄17373742694…… #首先设置未知数 amount = 0 total_cost = 0 money_saved = 0 #设置输入 price = input (“输入价格”:) while price > 0: total_cost = total_cost + price amount +=1 if amount < 4: total_off = total_cost * (1- amount/10.00) #如果有变量 else: total_off =...
@贡钥5781:用python编程求多项式sn=1 - 3+5 - 7+9 - 11+……的前100项和 -
郜狄17373742694…… 见下在的代码 1 2 3 4 5 6 7 he =0 forn inrange(0,100): if(n %2==0): he +=2*n +1 else: he -=2*n +1 print(he)
@贡钥5781:Print the first non - digit in string s. (Python编程) -
郜狄17373742694…… def non_digits(s): for a in s: if not a.isdigit(): print a return
@贡钥5781:Python编程:输入三角形的边a, b, c,求夹角C -
郜狄17373742694…… 我刚做完这题.我的答案: import math a = float(raw_input()) b = float(raw_input()) c = float(raw_input()) degree = math.degrees(math.acos((a**2 + b**2 - c**2) / (2 * a * b))) print '{0:.{1}f}'.format(degree, 1)OJ测试通过.
@贡钥5781:python编程求100 - 1000范围内被9除余7、被5除3的最小两个整数? -
郜狄17373742694…… #求100-1000范围内被9除余7、被5除3的最小两个整数 for i in range(100,1000): if i%9==7: print('{}除以9余7'.format(i)) break #跳出循环 for j in range(100,1000): if j%5==3: print('{}除以5余3'.format(j)) break#跳出循环
@贡钥5781:用python编写程序 -
郜狄17373742694…… s=read("字符串") str=read("子字符串:") print(s.replace(str,' '))
@贡钥5781:如何运行Python程序 -
郜狄17373742694…… 1. 使用Python自带的IDLE 在开始-->程序-->Python2.5(视你安装的版本而不同)中找到IDLE(Python GUI),点击后弹出如下窗体:在>>>提示符后输入代码,回车,就可以执行此代码.IDLE支持语法高亮,支持自动缩进,支持方法提示,不过提...
@贡钥5781:Python编程#输出n以内的所有质数. -
郜狄17373742694…… 质数又称素数.指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数. 一般正常人的解法是两次循环,假设求小于N的所有素数.一次用N-1之间的所有数去除,如果能被整除这个数肯定不是素数.否则是素数.