Skip to content

Instantly share code, notes, and snippets.

@code-ghalib
Last active October 12, 2019 18:00
Show Gist options
  • Save code-ghalib/88b5aba07e2ee530c278b788fd9b17e9 to your computer and use it in GitHub Desktop.
Save code-ghalib/88b5aba07e2ee530c278b788fd9b17e9 to your computer and use it in GitHub Desktop.
malz.py
name = input("Enter your name: ")
def grade_from_percentage(p):
if p < 60.0:
return "n F"
elif p <= 64.0:
return "D"
elif p <= 69.0:
return "D+"
elif p <= 74.0:
return "C"
elif p <= 79.0:
return "C+"
elif p <= 84.0:
return "B"
elif p <= 89.0:
return "B+"
elif p <= 94.0:
return "n A"
else:
return "n A+"
def quiz():
with open("Ans1.txt","r") as topic1:
score = 0
Ans = topic1.readlines()
print("Q-1. Which of the following represents a distinctly identifiable entity in the real world?\n A. Class,\n B. Object,\n C. Method,\n D. Data field")
useranswer = input("Answer: ")
if useranswer == Ans[0].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-2. Which of the following represents a template, blueprint, or contract that defines objects of the same type?\n A. Class,\n B. Object,\n C. Method,\n D. Data field")
useranswer = input("Answer: ")
if useranswer == Ans[1].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-3. Which of the following keywords mark the beginning of the class definition?\n A. Def,\n B. Return,\n C. Class,\n D. All of the above")
useranswer = input("Answer: ")
if useranswer == Ans[2].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-4. Which of the following is required to create a new instance of the class?\n A. Constructor,\n B. Class,\n C. Value Returning Method,\n D. None Method")
useranswer = input("Answer: ")
if useranswer == Ans[3].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-5. Which of the following statements is most accurate for the declaration x = Circle()?\n A. x contains an int value,\n B. x contains an object of the Circle type,\n C. x contains a reference to a Circle object,\n D. You can assign an int value to x")
useranswer = input("Answer: ")
if useranswer == Ans[4].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-6. What relationship correctly fits for University and Professor?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above")
useranswer = input("Answer: ")
if useranswer == Ans[5].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-7. What relationship is suited for Course and Faculty?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. None of the above")
useranswer = input("Answer: ")
if useranswer == Ans[6].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-8. What relationship is best suited for Employee and Person?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. None of the above")
useranswer = input("Answer: ")
if useranswer == Ans[7].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-9. What relationship is best suited for House and Door?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above")
useranswer = input("Answer: ")
if useranswer == Ans[8].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Q-10. What relationship is appropriate for Fruit and Papaya?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above")
useranswer = input("Answer: ")
if useranswer == Ans[9].rstrip():
print ("Correct\n")
score = score + 10
else:
print ("Incorrect\n")
print("Your total score is", score)
percentage = (score/100)*100
print("The percentage is", percentage)
grade = grade_from_percentage(percentage)
print("You have achieved a" + grade + " grade in the quiz")
with open("reports.txt","a") as reports:
reports.write("\n" + name + " achieved a" + grade + " grade in the quiz")
with open("reports.txt","a") as reports:
reports.write("\n" + name + " " + "did the quiz and" + " " + "achieved a score of" + " " + str(score))
reports.write("\n" + name + " " + "did the quiz and" + " " + "achieved a percentage of" + " " + str(percentage))
quiz()
def grade_from_percentage(p):
if p < 60.0:
return "n F"
elif p <= 64.0:
return " D"
elif p <= 69.0:
return " D+"
elif p <= 74.0:
return " C"
elif p <= 79.0:
return " C+"
elif p <= 84.0:
return " B"
elif p <= 89.0:
return " B+"
elif p <= 94.0:
return "n A"
else:
return "n A+"
def quiz(questions,name):
score = 0
qno = 0
with open("Ans1.txt","r") as answers:
for q in questions:
qno += 1
print("Q-" + qno + ". " + q)
ans = input("Answer: ")
if ans == answers.readlines()[0].rstrip():
print("Correct\n")
score += 10
else:
print("Incorrect\n")
print("Your total score is "+score)
percentage = (score/100)*100
print ("The percentage is "+percentage+"%")
print ("You have achieved a" + grade + " grade in the quiz")
with open("reports.txt","a") as reports:
reports.write("\n" + name + " did the quiz and achieved a" + grade + " grade in the quiz")
reports.write("\n" + name + " did the quiz and achieved a score of " + str(score))
reports.write("\n" + name + " did the quiz and achieved a percentage of " + str(percentage))
questions = [
"Which of the following represents a distinctly identifiable entity in the real world?\n A. Class,\n B. Object,\n C. Method,\n D. Data field",
"Which of the following represents a template, blueprint, or contract that defines objects of the same type?\n A. Class,\n B. Object,\n C. Method,\n D. Data field",
"Which of the following keywords mark the beginning of the class definition?\n A. Def,\n B. Return,\n C. Class,\n D. All of the above",
"Which of the following is required to create a new instance of the class?\n A. Constructor,\n B. Class,\n C. Value Returning Method,\n D. None Method",
"Which of the following statements is most accurate for the declaration x = Circle()?\n A. x contains an int value,\n B. x contains an object of the Circle type,\n C. x contains a reference to a Circle object,\n D. You can assign an int value to x",
"What relationship correctly fits for University and Professor?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above",
"What relationship is suited for Course and Faculty?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. None of the above",
"What relationship is best suited for Employee and Person?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. None of the above",
"What relationship is best suited for House and Door?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above",
"What relationship is appropriate for Fruit and Papaya?\n A. Association,\n B. Composition,\n C. Inheritance,\n D. All of the above"
]
name = input("Enter your name: ")
quiz(questions,name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment