[英]How do I seperate 2 outputs from each other in python
gate = input("Choose\nA) for 'AND' gate and\nB) for 'OR' gate\n")
if gate == "A":
val1 = float(input("Whats your A value?"))
val2 = float(input("Whats your B value?"))
if val1 == 0 and val2 == 0:
print("Your C value is 0")
if val1 == 0 and val2 == 1:
print("Your C value is 0")
if val1 == 1 and val2 == 0:
print("Your C value is 0")
if val1 == 1 and val2 == 1:
print("Your C value is 1")
#Right here is the error, I need something to separate top process from bottom process
if gate == "B":
val1 = float(input("Whats your A value?"))
val2 = float(input("Whats your B value?"))
if val1 == 0 and val2 == 0:
print("Your C value is 0")
if val1 == 0 and val2 == 1:
print("Your C value is 1")
if val1 == 1 and val2 == 1:
print("Your C value is 1")
if val1 == 1 and val2 == 0:
print("Your C value is 1")
So everything works, If I just put the if gate == "A":
section and not the if gate == "B":
part it work. 因此一切正常,如果我只是将
if gate == "A":
部分而不是if gate == "B":
部分放入,它将正常工作。 From my experience in C, I feel like I need something that seperates both tasks / processes from each other, may someone tell me the line of code, I've searched many places on the internet and still haven't found a solution. 根据我在C语言方面的经验,我觉得我需要一些将两个任务/流程彼此分开的东西,也许有人告诉我这行代码,我已经在互联网上搜索了很多地方,但仍然没有找到解决方案。
In order to separate the two processes, this is probably what you want to do: 为了分离这两个过程,这可能是您想要做的:
def process_A():
val1 = int(input("Whats your A value?"))
val2 = int(input("Whats your B value?"))
if val1 == 0 and val2 == 0:
print("Your C value is 0")
if val1 == 0 and val2 == 1:
print("Your C value is 0")
if val1 == 1 and val2 == 0:
print("Your C value is 0")
if val1 == 1 and val2 == 1:
print("Your C value is 1")
def process_B():
val1 = int(input("Whats your A value?"))
val2 = int(input("Whats your B value?"))
if val1 == 0 and val2 == 0:
print("Your C value is 0")
if val1 == 0 and val2 == 1:
print("Your C value is 1")
if val1 == 1 and val2 == 1:
print("Your C value is 1")
if val1 == 1 and val2 == 0:
print("Your C value is 1")
gate = input("Choose\nA) for 'AND' gate and\nB) for 'OR' gate\n")
if gate == "A":
process_A()
elif gate == "B":
process_B()
Input A --> A process: 输入A->一个过程:
Choose
A) for 'AND' gate and
B) for 'OR' gate
B
Whats your A value?0
Whats your B value?0
Your C value is 0
Input A --> A process: 输入A->一个过程:
Choose
A) for 'AND' gate and
B) for 'OR' gate
A
Whats your A value?1
Whats your B value?1
Your C value is 1
gate = raw_input("Choose\nA) for 'AND' gate and\nB) for 'OR' gate\n")
if gate == "A":
val1 = input("Whats your A value?")
val2 = input("Whats your B value?")
if val1 == 1 and val2 == 1:
print("Your C value is 1")
else:
print("Your C value is 0")
#Right here is the error, I need something to separate top process from bottom process
if gate == "B":
val1 = input("Whats your A value?")
val2 = input("Whats your B value?")
if val1 == 0 and val2 == 0:
print("Your C value is 0")
else:
print("Your C value is 1")
I changed the input for raw_input for get the letter like string, and I compressed the code because no need more validation when have the same response. 我更改了raw_input的输入以获取类似字符串的字母,并且压缩了代码,因为在具有相同响应时无需进行更多验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.