Python Probability

Suppose every day you wake up and you are randomly in a GOOD mood 60% of the time or in a BAD mood 40% of the time. Furthermore, anytime you have a quiz or test in a course, the grade you receive is also random based on the following:

If you take a quiz or exam when you are in a GOOD mood,

  • you get a 100 on 80% of such days
  • you get a 75 on 20% of such days

If you take an exam when you are in a BAD mood,

  • you get a 100 on 20% of such days
  • you get a 75 on 30% of such days
  • you get a 50 on 50% of such days

Write python code that does the following

  1. Write a function to generate your grade on a random quiz/exam day - name this function takeOneTest()

Comments: this function may or may not have any parameters.
when you run this function, it will output one random test score (a 50, 75, or 100).
there are multiple ways for this function, consider using the runif() or sample() functions for the random components and if-else structures.

  1. Write a 2nd function to calculates an arbitrary number of exam results - name this function SemesterGrades(num_tests).

Comments: This function should call takeOneTest() a user specified number of times (num_tests).
when you run this function, it will output num_tests values, each value corresponding to a single random test score. This can be done in multiple ways as well [while() or for() ].
so for example, output from SemesterGrades(6) may result in: 100 50 75 75 100 75

This is some code I have but in R
GorBday ← sample(c(“Good”, “Bad”), size=1, prob=c(0.60, 0.40))

This is the code to determines test scores on good days

GoodDayTscore ← sample(c(“100”, “75”), size=1, prob=c(0.80, 0.20))

This is the code that determines test scores on bad days

BadDayTscore ← sample(c(“100”, “75”, “50”), size=1, prob=c(0.20, 0.30, 0.50))

Hi, do you have a question or so?
Please be aware we are not doing your homework or other assignments but we might be willing to help - if you include some specific questions.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.