Python Forum
I have a simple problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have a simple problem
#1
Hello
please help me
Condition 1 (if the result is between 3 and 5)
Condition 2 (and has been in contact with an infected person),

print(he/she must
Self-isolate for 14 days and get tested for covid-19.)
Condition 1 The problem in condition 2 is not fulfilled, meaning if a vertex by entering 0 is met, all conditions are not fulfilled, even if a vertex is entered by 1 all the conditions are met.
-----------------------------------------------------------------------------
a = input("name:")
y = input("Age:")
z = input("Sex:")
x = open("c19.txt", "w")
print("**Notice 1 mean yes, 0 mean no.** ")
def sum(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9):
    q = (Q1 + Q2 + Q3 + Q4 + Q5 + Q6 + Q7 + Q8 + Q9)
    if (q >= 3) or (q <= 5) and (Q1 == 1): # Highligted in red
        x = open("c19.txt", "w")
        x.write("name: " + a + "\n" + "Age: " + y + "\n""Sex: " + z + "\n")
        x.write("Result:\t"+"he/she must isolate him/her self for 14 days and do covid-19 test.")
        x.close()
    elif q > 5:
        x = open("c19.txt", "w")
        x.write("name: " + a + "\n" + "Age: " + y + "\n""Sex: " + z + "\n")
        x.write("Result:\t"+"he/she must do covid-19 test, Mybe he/she infected by covid-19.")
        x.close()
    elif q < 3:
        x = open("c19.txt", "w")
        x.write("name: " + a + "\n" + "Age: " + y + "\n""Sex: " + z + "\n")
        x.write("Result:\t"+"he/she must isolate him/her self for 5 days if no more symptoms show,then he/she are not infected.")
        x.close()

n3 = (int)(input("if was in contact with an infected person:"))
n4 = (int)(input("Do you have a fever:"))
n5 = (int)(input("Do you have a cough:"))
n6 = (int)(input("Do you have shortness of breath or difficulty breathing:"))
n7 = (int)(input("Do you have Fatigue:"))
n8 = (int)(input("Do you have muscle or body aches:"))
n9 = (int)(input("Do you have a headache:"))
n10 = (int)(input("Do you have a loss of taste or smell:"))
n11 = (int)(input("Do you have a sore throat:"))

sum(n3, n4, n5, n6, n7, n8, n9, n10, n11)
Yoriz write Jul-17-2021, 07:37 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
n3 = (int)(input("if was in contact with an infected person:"))
The above won't work, to use the function int it must be called with a argument.
Example
int('1')
Reply
#3
Can you add it to the code above and republish it to make it clear to me? Thank you
Reply
#4
What's with the really poor variable names (pretty much all of them)? Use names that are meaningful - for example, if a variable is going to store a name, why not just call it name? Good names make it easier to read and understand code.
Reply
#5
It's your homework you should try and change the code yourself based on the hint of how int works, that way you will learn more.
Another hint: you want to turn the result returned by input into an int
Reply
#6
The condition is half fulfilled, but the result of m3 must be 1 or not all of the condition are met

Notice ** It's not homework
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  simple function problem stereokim123 5 3,258 Aug-26-2021, 04:44 PM
Last Post: naughtyCat
  Simple problem with functions and returns danlopek14q 10 6,735 Mar-17-2021, 05:32 PM
Last Post: danlopek14q
  Problem with a simple script Niko047 2 3,328 Jul-21-2017, 09:02 PM
Last Post: Niko047

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020