文章目录
请输入两个数和一个符号,完成两个数的+ - * / % // **
from secrets import choice
a=int(input("请输入第一个数字:"))
b=int(input("请输入第二个数字:"))
c=str(input("请在以下字符中选择一个:+ - * / % // ** :"))
while c:
if c=="+":
print("两个数字之和为:%s"%(a+b))
elif c=="-":
print("两个数字之和为:%s"%(a-b))
elif c=="*":
print("两个数字之和为:%s"%(a*b))
elif c=="/":
print("两个数字之和为:%s"%(a/b))
elif c=="%":
print("两个数字之和为:%s"%(a%b))
elif c=="//":
print("两个数字之和为:%s"%(a//b))
elif c=="**":
print("两个数字之和为:%s"%(a**b))
break

展示商品信息(折扣)->输入商品价格->输入购买数量->提示付款
输入付款金额->打印购买小票(扩展)
from random import choice
print("英雄商城首页")
print("英雄商城英雄列表")
print('''
英雄商城英雄列表
~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~
编号 姓名 昵称 价格 折扣 库存 描述
1 纳尔 迷失之牙 3500 9.5 100 丛林不会原谅盲目与无知
2 锐雯 放逐之刃 4000 9.5 100 她是残忍高效的战士
3 薇恩 暗夜猎手 3500 9.56 100 这个世界不想人们想象的那么美好
4 扎克 生化魔人 3000 9.8 100 即使你没有脊柱,你也必须站起来
5 杰斯 未来守护者 2500 6.5 100 武装着睿智与魅力,你的选择没有错
~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~
''')
choice==int(input("请您选择商品:"))
a=int(input("请输入商品价格:"))
num=int(input("请输入购买数量:"))
c=float(input("请输入您购买的商品的折扣:"))
payways=str(input("请您选择以下的付款方式:支付宝、微信、或者是银行卡:"))
if payways=="支付宝":
print("您选择的支付方式为:支付宝,您需要支付的金额为:%s"%(a*num*c/10))
elif payways=="微信":
print("您选择的支付方式为:微信,您需要支付的金额为:%s"%(a*num*c/10))
elif payways=="银行卡":
print("您选择的支付方式为:银行卡,您需要支付的金额为:%s"%(a*num*c/10))
else:
print('请输入正确的支付方式:')

用户输入身高(m),体重(kg)
计算公式:BMI = 体重 / 身高^2
BMI < 18.5:过轻
18.5≤ BMI <24:正常
24 ≤ BMI <27:过重
27 ≤ BMI < 30:轻度肥胖
30 ≤ BMI < 35:中度肥胖
BMI ≥ 35:重度肥胖
from tokenize import Double
print("**********************健康计划**********************")
a=float(input("请输入您的身高:"))
b=float(input("请输入您的体重:"))
BMI = b/(a*a)
if BMI <18.5:
print("您的体重过轻")
elif 18.5<=BMI <24:
print("您的体重正常")
elif 24 <= BMI <27:
print("您的体重过重")
elif 27 <=BMI <30:
print("您的体重轻度肥胖")
elif 30 <= BMI < 35:
print("您的体重中度肥胖")
elif BMI >=35:
print("您的体重重度肥胖")
else:
print("请输入正确答案!!")

1、
*
**
***
****
*****
******
from operator import index
layer = int(input("请输入您要打印的层数:"))
index = 1
while index <= layer:
# 打印每一层的*的个数
j = 1
while j <= index:
print("*", end="")
j += 1
print()
# print("*" * index)
index += 1

2、
*
***
*****
*******
*********
layer = int(input("请输入您好打印的层数:"))
i = 1
while i <= layer:
# 求出空格的数量
a = layer - i
j = 1
while j <= a:
print(" ", end="")
j += 1
# 求*的数量
b = 2 * i - 1
j = 1
while j <=b:
print("*", end="")
j += 1
print()
i += 1

3、
*********
*******
*****
***
*
layer = int(input("请输入您好打印的层数:"))
for i in range(layer, 0, -1):
# 求出空格的数量
a = layer - i
# 求*的数量
b = 2 * i - 1
print(" "*a + "*"*b)

4、
*
***
*****
*******
*********
*******
*****
***
*
layer= int(input("请输入您要打印的层数"))
b = layer
c = layer
for i in range(1, layer + 1):
print(" " * (b - 1), "*" * (2 * i - 1))
b -= 1
if i == layer:
for y in range(1, layer):
print(" " * y, "*" * (2*c-3))
c -= 1

5、
*
* *
* *
* *
* *
* *
* *
* *
*
layer = int(input("请输入您要打印的层数:"))
b = layer
c = layer
print(" " * (layer - 1), "*")
for i in range(2, layer+1):
print(" " * (b - 1) + "*" + " " * (2 * i - 3) + "*")
b -= 1
if i == layer:
for y in range(2, layer):
print(" " * y+"*"+" "*(2*c-5)+ "*" )
c -= 1
print(" "*layer+"*")

6、
*
***
* * *
* * *
*********
* * *
* * *
***
*
layer= int(input('请输入您要输入的层数: '))
m = t = 2 * layer-1
while m >= 1:
if(m == t or m == 1):
print(' ' * layer + '*' + ' ' * 4 * (layer-1))
elif m == layer:
print(' '+' *' * (2 * layer - 2))
elif m > layer:
print(' ' * (m - layer + 1) + '*' +' ' * (t - m - 1) + ' *' +' ' * (t - m - 1) + ' *')
else:
print(' ' * (layer - m + 1) + '*' + ' ' * ((2 * m - 3) // 2) + ' *' + ' ' * ((2 * m - 3) // 2) + ' *')
m -= 1

num = int(input("请输入数字:"))
for i in range(2,num):
if num%i==0:
print("这个不是质数!!")
break
else:
print("这个数是质数!!")

from calendar import month
month=int(input("请输入月份:"))
for i in range(1,12):
if month==1:
print("%s"%month+"月"+"是冬季!!")
elif month==2:
print("%s"%month+"月"+"是冬季!!")
elif month==3:
print("%s"%month+"月"+"是春季!!")
elif month==4:
print("%s"%month+"月"+"是春季!!")
elif month==5:
print("%s"%month+"月"+"是夏季!!")
elif month==6:
print("%s"%month+"月"+"是夏季!!")
elif month==7:
print("%s"%month+"月"+"是夏季!!")
elif month==8:
print("%s"%month+"月"+"是夏季!!")
elif month==9:
print("%s"%month+"月"+"是秋季!!")
elif month==10:
print("%s"%month+"月"+"是秋季!!")
elif month==11:
print("%s"%month+"月"+"是冬季!!")
elif month==12:
print("%s"%month+"月"+"是冬季!!")
break
if month>12:
print("请输入正确的月份!!")

username=str(input("请输入用户名:"))
while username=="admin":
password=int(input("请输入您的密码:"))
if password==88888:
print("您输入的密码是正确的!")
break
elif password!=88888:
print("密码错误")
break
else:
print('用户不存在')

for i in range(1000, 10000):
hundredth = i % 1000 // 100
ten = i % 100 // 10
if hundredth == 3 and ten == 6 and i % 6 == 0:
print(f"{i}")

a = input("请输入一个四位数:")
while True:
b = int(a)
break
num4 = b // 1000
num3 = b // 100 - b // 1000 * 10
num2 = b // 10 - b // 100 * 10
num1 = b - b // 10 * 10
print(str(num1)+str(num2)+str(num3)+str(num4))

a=int(input("请输入数字a:"))
b=int(input("请输入数字b:"))
while True:
if a/b or a+b>1000:
print("输出的值为:%s"%a)
break
else:
print("输出的值为:%s"%b)

grade=int(input("请输入成绩:"))
if grade>100 or grade<0 :
print("赵同学,不要开玩笑!!")
elif grade==100:
print('赵同学,你爸爸要给你买车啦!!')
elif grade>=90:
print('赵同学,你妈妈要给你买MP4啦!!')
elif grade<90 and grade>=60:
print('赵同学,你妈妈要给你买本参考书啦!!')
elif grade<60 and grade>=0:
print('想啥啦,回去准备挨打吧!!')
else:
print("不要调皮啦,请输入正确成绩!!")

num = int(input("请输入数字:"))
if num%2==0 :
print('该数是偶数!!')
for num in range(1,num+1):
if num %3 ==0:
print("该数从1到该数是3的倍数有:%s"%num)
else:
print("该数是奇数!!")
for num in range(1,num+1):
if num % 5==0:
print("该数从1到该数是5的倍数有:%s"%num)

from cmath import sqrt
import math
a=float(input("请输入边长a:"))
b=float(input("请输入边长b:"))
c=float(input("请输入边长c:"))
if a+b>c and a+c>b and b+c>a:
print("该三角形是三角形")
p=(a+b+c)/2
s1=p*(p-a)*(p-b)*(p-c)
s=math.sqrt(s1)
print('面积:'+str(s))
print('周长:' + str(2*p))
else:
print("该三角形不是三角形!!")

from secrets import choice
c_money=35
t_money=120
while True:
num=int(input("请输入您需要商品的总数:"))
clothes=int(input("请输入您需要衣服的件数:"))
trousers=int(input("请输入您需要裤子的件数:"))
if num==1 :
if clothes==1 or trousers==0:
print("您需要支付:衣服:%s"%(c_money)*clothes+"元,"+"裤子:%s"%(t_money)*trousers+"元,"+"您需要支付的总金额为:%s"%(c_money*clothes+t_money*trousers))
elif clothes==0 or trousers==1:
print("您需要支付:衣服:%s"%(c_money)*clothes+"元,"+"裤子:%s"%(t_money)*trousers+"元,"+"您需要支付的总金额为:%s"%(c_money*clothes+t_money*trousers))
continue
elif num==2:
if clothes==0 or trousers==2:
print("您需要支付:衣服:%s"%((c_money)*clothes*9/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes+t_money*trousers)*9/10))
elif clothes==1 or trousers==1:
print("您需要支付:衣服:%s"%(c_money)*clothes+"元,"+"裤子:%s"%(t_money)*trousers+"元,"+"您需要支付的总金额为:%s"%(c_money*clothes+t_money*trousers))
elif clothes==2 or trousers==0:
print("您需要支付:衣服:%s"%((c_money)*clothes*9/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes+t_money*trousers)*9/10))
continue
elif num==3:
if clothes==0 or trousers==3:
print("您需要支付:衣服:%s"%((c_money)*clothes*9/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes+t_money*trousers)*9/10))
elif clothes==1 or trousers==2:
print("您需要支付:衣服:%s"%((c_money*clothes))+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes+t_money*trousers)*9/10))
elif clothes==2 or trousers==1:
print("您需要支付:衣服:%s"%((c_money)*clothes*9/10)+"元,"+"裤子:%s"%(t_money)*trousers+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes*9/10)+t_money*trousers))
elif clothes==3 or trousers==0:
print("您需要支付:衣服:%s"%((c_money)*clothes*8/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes*8/10)+t_money*trousers))
continue
elif num>=4:
# if clothes==1 or trousers>=2:
# print("您需要支付:衣服:%s"%((c_money)*clothes)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes)+t_money*trousers*9/10))
if clothes==2 or trousers==2:
print("您需要支付:衣服:%s"%((c_money)*clothes*8/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes*8/10)+(t_money*trousers*9/10)))
elif clothes>2 or trousers>2:
print("您需要支付:衣服:%s"%((c_money)*clothes*8/10)+"元,"+"裤子:%s"%((t_money)*trousers*9/10)+"元,"+"您需要支付的总金额为:%s"%((c_money*clothes*8/10)+(t_money*trousers*9/10)))
else:
print("您输入有误")

for x in range(1,36):
for y in range(1,36):
if x+y==35 and 2*x+4*y==94:
print ("鸡有:%s"%x+"个")
print("兔有:%s"%y+"个")

import random
# 生成随机数
computer = random.randint(1, 100)
while True:
my = int(input("请输入您要猜的数:"))
if my == computer:
print("恭喜您,猜对了")
choice = input("您是否继续?结束请输入(n/N),按任意键继续:")
if choice == "N" or choice == "n":
break
else:
# 重新生成随机数
computer = random.randint(1, 100)
elif my > computer:
print("对不起,猜大了")
else:
print("对不起,猜小了")
print("GAME OVER!!!")

import random
# 生成随机数
computer = random.randint(1, 3)
while True:
my = int(input("请输入以下数字:1代表石头、2代表剪刀、3代表布:"))
if my == computer :
print("咱们成平局了,电脑的随机数为:%s"%computer)
choice = input("您是否继续?结束请输入(n/N),按任意键继续:")
if choice == "N" or choice == "n":
break
else:
computer = random.randint(1,3)
elif 4>my>computer:
print("恭喜,您赢了!!电脑的随机数为:%s"%computer)
elif my>=4 or my<0:
print("输入错误,请输入在1~3的数字!!!")
print("GAME OVER!!!")

a a^2 a^3
1 1 1
2 4 8
3 9 27
# 方法一;
for a in range(1,4):
print("a的值、平方、立方分别为:%s,%s,%s"%(a,a*a,a*a*a))
# 方法二:
a=int(input("请输入您想要输入的数字:"))
ji=0
while True:
print("a的值、平方、立方分别为:%s,%s,%s"%(a,a*a,a*a*a))
ji=ji+1
break

year=int(input("请输入年份:"))
if (year % 4==0 and year % 100!=0) or year % 400==0:
print("该年份是闰年")
else:
print("该年不是闰年")

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我脑子里浮现出一些关于一种新编程语言的想法,所以我想我会尝试实现它。一位friend建议我尝试使用Treetop(Rubygem)来创建一个解析器。Treetop的文档很少,我以前从未做过这种事情。我的解析器表现得好像有一个无限循环,但没有堆栈跟踪;事实证明很难追踪到。有人可以指出入门级解析/AST指南的方向吗?我真的需要一些列出规则、常见用法等的东西来使用像Treetop这样的工具。我的语法分析器在GitHub上,以防有人希望帮助我改进它。class{initialize=lambda(name){receiver.name=name}greet=lambda{IO.puts("He
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
似乎无法为此找到有效的答案。我正在阅读Rails教程的第10章第10.1.2节,但似乎无法使邮件程序预览正常工作。我发现处理错误的所有答案都与教程的不同部分相关,我假设我犯的错误正盯着我的脸。我已经完成并将教程中的代码复制/粘贴到相关文件中,但到目前为止,我还看不出我输入的内容与教程中的内容有什么区别。到目前为止,建议是在函数定义中添加或删除参数user,但这并没有解决问题。触发错误的url是http://localhost:3000/rails/mailers/user_mailer/account_activation.http://localhost:3000/rails/mai
我正在检查一个Rails项目。在ERubyHTML模板页面上,我看到了这样几行:我不明白为什么不这样写:在这种情况下,||=和ifnil?有什么区别? 最佳答案 在这种特殊情况下没有区别,但可能是出于习惯。每当我看到nil?被使用时,它几乎总是使用不当。在Ruby中,很少有东西在逻辑上是假的,只有文字false和nil是。这意味着像if(!x.nil?)这样的代码几乎总是更好地表示为if(x)除非期望x可能是文字false。我会将其切换为||=false,因为它具有相同的结果,但这在很大程度上取决于偏好。唯一的缺点是赋值会在每次运行
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
假设我在Ruby中有这个each循环。@list.each{|i|putsiifi>10breakend}我想循环遍历列表直到满足条件。这让我感到“不像Ruby”,因为我是Ruby的新手,是否有Ruby方法可以做到这一点? 最佳答案 您可以使用Enumerable#detect或Enumerable#take_while,取决于您想要的结果。@list.detect{|i|putsii>10}#Returnsthefirstelementgreaterthan10,ornil.正如其他人所指出的,更好的风格是先进行子选择,然后再对其
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。