In: Computer Science
5. Write a program that prints all numbers between 27 and 78, one number per line.
6. In questions 6,7 the following list is used: [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12]
7. Using “for” loop, write program that finds the smallest number in the list.
8. Using “for” loops, calculate arithmetic mean of all numbers in the list. Do not use built-in function in Python.
9. For this question envision you are creating a dummy alert to help the doctor determine if patient needs a mammogram or not: Ask the user to answer the following questions:
• "What is your patient’s gender? Please answer F for female, M for male " and store it in a variable "gender".
• "What is your patient’s age? " store it in a variable "age"
• "Does your patient have family history of breast cancer? Please answer with True or False " store it in a variable name "history" The program should display the following alert messages based on conditions:
• If patient is female and over 40 the system should alert the doctor to "consider ordering mammogram”
• If the patient is female but younger than 40 the program should go to next step and consider patient family history to determine if mammogram is recommended. If patient has family history of breast cancer the program should display a message "consider mammogram because of family history". If not just display "my not need mammogram" • In any other case the alert should say "no mammogram order recommended". Suggestion: Attention to the variable types when you input and compare.
I have written the program using PYTHON PROGRAMMING LANGUAGE.
OUTPUT :
CODE :
#Question 5
# for loop to print the numbers from 27 to 78 inclusive
for number in range(27,78+1):
print(number)#to print on console
#Question 6,7,8
#declared required variables
mean = 0
length = 0
smallest = 9999999
list_numbers = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12]
for number in list_numbers:
length+=1
if(smallest> number):
smallest = number#smallest number
mean +=number
mean = mean / length#mean
print("\nSmallest Number in the list is {:.2f}\nMean of all numbers {:.2f}".format(smallest,mean))
#Question 9
#taking user input for gender age and history
gender = input("\nWhat is your patient’s gender? Please answer F for female, M for male : ")
age = int(input("What is your patient’s age? : "))
history = input("Does your patient have family history of breast cancer? Please answer with True or False : ")
#written conditions based on the description given in the question.
print("\n")
if(gender.lower() == "f" and age>=40):
print("consider ordering mammogram")
elif(gender.lower() == "f" and age<40):
if(history.lower() == "true"):
print("consider mammogram because of family history")
else:
print("may not need mammogram")
else:
print("no mammogram order recommended")
Thanks..