if month == 1 or 10:
month1 = 0
if month == 2 or 3 or 11:
month1 = 3
if month == 4 or 7:
month1 = 6
if month == 5:
month1 = 1
if month == 6:
month1 = 4
if month == 8:
month1 = 2
if month == 9 or 12:
month1 = 5
Run Code Online (Sandbox Code Playgroud)
此代码始终返回month1等于5.我对编程很陌生,我做错了什么?(我想这涉及12是最高数字的事实,但==意味着等于对吗?)
手头的任务很简单,制作一个简短的程序,要求提供cpsc先决条件(数字217,219或233)和数学先决条件(217或251),如果你有一个这样的类作为先决条件,那么应该说先决条件遇到,如果没有,则不满足先决条件.我的代码如下(不要笑,字面意思是最大的python noob):
cpsc=input("Which cpsc course have you taken (only pick one): ")
math=input("which math course have you taken (only pick one): ")
if cpsc==(217 or 219 or 233) and math ==(217 or 251)
print("prerequisites met")
else:
print("prerequisites not met")
Run Code Online (Sandbox Code Playgroud)
每个输入我有它只是给了我别的打印,我假设它的一个问题,在比较中cpsc==和math==,我能做些什么,使这项工作?任何和所有的帮助将不胜感激.
我不确定为什么,但是当我执行这段代码时没有任何反应.
while (True) :
choice = str(input("Do you want to draw a spirograph? (Y/N) "))
if choice == 'n' or 'N' :
break
elif choice == 'y' or 'Y' :
<CODE>
else :
print("Please enter a valid command.")
choice = input("Do you want to draw a spirograph? (Y/N)")
Run Code Online (Sandbox Code Playgroud) 我是编程新手,我编写了一个程序来解决方程中的不同变量.我有"if""elif"和"else"设置来解决等式的不同部分.出于某种原因,它只会解决第一部分("if"部分)我将复制并粘贴下面的程序.
import math
print 'A=Pert Calculator'
print ''
print 'Created by Triton Seibert'
print ''
Y = raw_input('What letter would you like to solve for?: ')
if Y == 'A' or 'a' or '1':
print 'Solving for A'
print ''
P = float(raw_input('Set value for P (initial investment):'))
e = 2.71828
print ''
r = float(raw_input('Set value for r (rate):'))
print ''
t = float(raw_input('Set value for t (time in years):'))
print ''
ert = e**(r*t)
answer = P*ert
print …Run Code Online (Sandbox Code Playgroud) 我一直试图了解是否可以使用类似于我在下面演示的语句的 if 语句。我的理解是不是?
for i in range(10):
if i == (3 or 5) or math.sqrt(i) == (3 or 5):
numbers.append(i)
Run Code Online (Sandbox Code Playgroud)
使用这段代码,我只能得到数字3& 9,而我应该得到3, 5, 9. 是否有另一种方法可以不列出下面的代码?
for i in range(10):
if i == 3 or i == 5 or math.sqrt(i) == 3 or math.sqrt(i) == 5:
numbers.append(i)
Run Code Online (Sandbox Code Playgroud) 我想看看一个函数是否返回一个整数,该整数的值应该是 1 或 0。
0 == (1 or 0)
0 等于 1 或 0,这听起来应该是真的,但事实并非如此。
为什么?以及如何正确地做我想做的事?
我做了一些代码,它将滚动两个模具并询问用户多少次.之后,它将询问用户是否想再次播放.由于某种原因,它应该没有突破其中一个while循环.
这是代码:
import random
again = True
rolls = 0
while again == True:
rolls = float(raw_input("How many times would you like the dice to roll?"))
while rolls >= 1:
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print dice1 , dice2
rolls = rolls - 1
again = raw_input("Would you like to play again?")
if again == "Yes" or "Y" or "yes" or "y":
again = True
else:
again = False
Run Code Online (Sandbox Code Playgroud)
你们中的任何人都可以帮助我吗?
有没有办法有效地做:
if operator != ('+' or '-' or '*' or '/'):
Run Code Online (Sandbox Code Playgroud)
无需做
operator != '+' and operator != '-' and operator != '*'
Run Code Online (Sandbox Code Playgroud) 有什么更好的我可以使用/导入?
while StrLevel != "low" or "medium" or "high":
StrLevel = input("Please enter low, medium, or high for the program to work; ")
Run Code Online (Sandbox Code Playgroud) 这是一个小程序,可用作算术计算器.我在这里读过以前的问题,但仍有疑问.在我的代码中,我在while循环中使用了'is'而不是==,但我的循环并没有停止.这有点出乎意料,因为如果用户在被要求输入时按'n',则变量ask将被新对象分配.如果有人可以查看代码并提供帮助,我将不胜感激.
def Add(x,y):
add = x+y
print("Answer:",add)
def Sub(x,y):
sub = x-y
print("Answer:",sub)
def Mult(x,y):
product = float(x*y)
print("Answer:",product)
def Div(x,y):
if y!=0:
div=float(x/y)
print("Answer:",div)
else:
print("Invalid input!")
ask='y'
while(ask is 'y' or 'Y'):
x=float(input("\nEnter x:"))
y=float(input("Enter y:"))
print("\nCALCULATOR:")
print("\nPlease select any of the following options:")
print("1.Add")
print("2.Subtract")
print("3.Multiplication")
print("4.Division")
opt=int(input("\nYour option:"))
if(opt is 1):
Add(x,y)
elif(opt is 2):
Sub(x,y)
elif(opt is 3):
Mult(x,y)
elif(opt is 4):
Div(x,y)
else:
print("Invalid option!")
ask=input("\nDo you want to continue?(y/n or Y/N)")
Run Code Online (Sandbox Code Playgroud)