If statement to find two input values
for i in range(0,3): stones=input("what stones do you have") if stones="reality stone" and "time stone": print("x")
ok so I store answers to input in one variable = stones and I need a statement which works if one input and another input are both present. here is my code..
See also questions close to this topic
-
Print Variables in For Loop
from matplotlib.pyplot import figure T10,T11,T12,T13 = nx.random_tree(10),nx.random_tree(11),nx.random_tree(12),nx.random_tree(13) T = [T10,T11,T12,T13] for t in T: print("The Pruefer Code for -", pruefer_code(t)) fig = figure() axis = fig.add_subplot(111) nx.draw(t, **opts, ax = axis)
Which results in:
The Pruefer Code for - [2, 8, 1, 9, 5, 5, 6, 8] The Pruefer Code for - [9, 6, 10, 7, 4, 8, 10, 4, 6] The Pruefer Code for - [4, 1, 4, 8, 11, 11, 8, 3, 4, 8] The Pruefer Code for - [8, 7, 11, 4, 2, 7, 9, 1, 5, 10, 7]
Plus the graphs - how would I amend the code so it'd say:
The Pruefer Code for - T10 [2, 8, 1, 9, 5, 5, 6, 8] The Pruefer Code for - T11 [9, 6, 10, 7, 4, 8, 10, 4, 6] The Pruefer Code for - T12 [4, 1, 4, 8, 11, 11, 8, 3, 4, 8] The Pruefer Code for - T13 [8, 7, 11, 4, 2, 7, 9, 1, 5, 10, 7]
Any help appreciated :)
-
Get number of packets received by ping command in python
I need a function that can return the number of packets received or loss percentage. Before I used the code below to get true/false if I receive any of the packets. This should work in Windows, but if somebody can do it suitable for Linux too, I would be thankful.
def ping_ip(ip): current_os = platform.system().lower() parameter = "-c" if current_os == "windows": parameter = "-n" command = ['ping', parameter, '4', ip] res = subprocess.call(command) return res == 0
-
Tkinter GUI unresponsive
I'm pretty new to python and tkinter, so pardon me if I'm being naive. I'm trying to make a GUI for solving an engineering design problem using a widely accepted method (implying the method is seamless). The code for this method takes 0.537909984588623 seconds when run independently (not in tkinter but normal code), and its not too complex or tangled. When I tried to modify this code to fit into a GUI using tkinter, it becomes unresponsive after I enter all the inputs and select a button, even though the program keeps running in the background. Also, when I forcefully close the GUI window, the jupyter kernel becomes dead. Heres a brief outline of my code:
-----------------------------------------------code begins------------------------------------------
from tkinter import * from scipy.optimize import fsolve import matplotlib import numpy as np import threading from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure import matplotlib.pyplot as plt matplotlib.use('TkAgg') import math class MyWindow(): def __init__(self, win): self.lbl1=Label(win, text='Alpha') self.lbl2=Label(win, text='xd') self.lbl3=Label(win, text='xw') self.lbl4=Label(win, text='xf') self.lbl5=Label(win, text='q') self.lbl6=Label(win, text='Reflux Factor') self.lbl7=Label(win, text='Tray Efficiency') self.lbl8=Label(win, text='Total Number of Stages') self.lbl9=Label(win, text='Feed Stage') self.t1=Entry(bd=3) self.t2=Entry(bd=3) self.t3=Entry(bd=3) self.t4=Entry(bd=3) self.t5=Entry(bd=8) self.t6=Entry(bd=8) self.t7=Entry(bd=8) self.t8=Entry(bd=8) self.t9=Entry(bd=8) self.btn1=Button(win, text='Total Number of Stages ', command=self.stagesN) self.lbl1.place(x=100, y=80) self.t1.place(x=300, y=80) self.lbl2.place(x=100, y=130) self.t2.place(x=300, y=130) self.lbl3.place(x=100, y=180) self.t3.place(x=300, y=180) self.lbl4.place(x=100, y=230) self.t4.place(x=300, y=230) self.lbl5.place(x=100, y=280) self.t5.place(x=300, y=280) self.lbl6.place(x=100, y=330) self.t6.place(x=300, y=330) self.lbl7.place(x=100, y=380) self.t7.place(x=300, y=380) self.lbl8.place(x=800, y=130) self.t8.place(x=790, y=170) self.lbl9.place(x=800, y=210) self.t9.place(x=790, y=260) self.btn1.place(x= 500, y= 75) def originalEq(self,xa,relative_volatility): ya=(relative_volatility*xa)/(1+(relative_volatility-1)*xa) return ya def equilibriumReal(self,xa,relative_volatility,nm): ya=(relative_volatility*xa)/(1+(relative_volatility-1)*xa) ya=((ya-xa)*nm)+xa return ya def equilibriumReal2(self,ya,relative_volatility,nm): a=((relative_volatility*nm)-nm-relative_volatility+1) b=((ya*relative_volatility)-ya+nm-1-(relative_volatility*nm)) c=ya xa=(-b-np.sqrt((b**2)-(4*a*c)))/(2*a) return xa def stepping_ESOL(self,x1,y1,relative_volatility,R,xd,nm): x2=self.equilibriumReal2(y1,relative_volatility,nm) y2=(((R*x2)/(R+1))+(xd/(R+1))) return x1,x2,y1,y2 def stepping_SSOL(self,x1,y1,relative_volatility,\ ESOL_q_x,ESOL_q_y,xb,nm): x2=self.equilibriumReal2(y1,relative_volatility,nm) m=((xb-ESOL_q_y)/(xb-ESOL_q_x)) c=ESOL_q_y-(m*ESOL_q_x) y2=(m*x2)+c return x1,x2,y1,y2 def stagesN(self): relative_volatility=float(self.t1.get()) nm=float(self.t7.get()) xd=float(self.t2.get()) xb=float(self.t3.get()) xf=float(self.t4.get()) q=float(self.t5.get()) R_factor=float(self.t6.get()) xa=np.linspace(0,1,100) ya_og=self.originalEq(xa[:],relative_volatility) ya_eq=self.equilibriumReal(xa[:],relative_volatility,nm) x_line=xa[:] y_line=xa[:] al=relative_volatility a=((al*q)/(q-1))-al+(al*nm)-(q/(q-1))+1-nm b=(q/(q-1))-1+nm+((al*xf)/(1-q))-(xf/(1-q))-(al*nm) c=xf/(1-q) if q>1: q_eqX=(-b+np.sqrt((b**2)-(4*a*c)))/(2*a) else: q_eqX=(-b-np.sqrt((b**2)-(4*a*c)))/(2*a) q_eqy=self.equilibriumReal(q_eqX,relative_volatility,nm) theta_min=xd*(1-((xd-q_eqy)/(xd-q_eqX))) R_min=(xd/theta_min)-1 R=R_factor*R_min theta=(xd/(R+1)) ESOL_q_x=((theta-(xf/(1-q)))/((q/(q-1))-((xd-theta)/xd))) ESOL_q_y=(ESOL_q_x*((xd-theta)/xd))+theta x1,x2,y1,y2=self.stepping_ESOL(xd,xd,relative_volatility,R,xd,nm) step_count=1 while x2>ESOL_q_x: x1,x2,y1,y2=self.stepping_ESOL(x2,y2,relative_volatility,R,xd,nm) step_count+=1 feed_stage=step_count x1,x2,y1,y2=self.stepping_SSOL(x1,y1,relative_volatility\ ,ESOL_q_x,ESOL_q_y,xb,nm) step_count+=1 while x2>xb: x1,x2,y1,y2=self.stepping_SSOL(x2,y2,relative_volatility\ ,ESOL_q_x,ESOL_q_y,xb,nm) step_count+=1 xb_actual=x2 stagesN=step_count-1 self.t8.insert(END, str(stagesN)) return window=Tk() mywin=MyWindow(window) window.title('DColumn') window.geometry("1500x1500") window.mainloop()
-------------------------------------------Code end--------------------------------------------
I read on other articles that using multiple threads brings down the load on mainloop and prevents freezing. But like I said, the code isnt very complex. Is it still because of everythings running on the mainloop? Or is there something more than meets the eye? Is multithreading the only way to go past this point?
Thanks in advance.