Saint Louis University |
Computer Science 1300/5001
|
Computer Science Department |
Note: All of these problems are for practice. You are freely encouraged to work together and you do not need to submit any of this work for a grade.
Write a program that asks a user for their favorite fruit, and then prints a response as follows:
What is your favorite fruit? apple I like apples too. |
Answer:
Write a program that asks the user to enter a temperature in Fahrenheit and reports the equivalent temperature in Celsius. You may use the formula $c = \frac{5}{9}(f - 32)$ for doing the conversion. A sample session might appear as follows:
Enter a temperature in Fahrenheit: 85 85 Fahrenheit is equivalent to 29.4444 Celsius. |
Answer:
Write a program that prompts the user for the radius of a circle, and which reports both the circumference and the area of that circle. As a reminder the circumference would be $2\pi r$ and the area would be $\pi r^2$. A sample session might appear as follows:
What is the radius of your circle? 5 A circle of radius 5 has circumference 31.4159 and area 78.53975. |
Answer:
There is a classic story (maybe it's even true) about mathematician Carl Gauss as a child. The story isthat a teacher, wanting to keep him busy for a long time, asked Gauss to compute the sumof the numbers from 1 to 100. Though the teacher presumed he would need to take time to repeatedly add one number at a time to the total, he returned quickly with the correct answer, answer, having effectively derived that the sum of the first $n$ numbers equals $\frac{n(n+1)}{2}$.
Though we will eventually learn to use loops in Python to automate repetitive tasks, we can follow Gauss's lead for now, to compute the sum of the first $n$ number without loops. Write a program that produces an interaction as follows.
Please enter a value for n: 100 The sum of the first 100 numbers is 5050. |
Answer:
Write a program that prompts the user for the length of the hypotenuse of a right triangle, and for the length of on of its legs, and which computes and outputs the length of the second leg. A sample session might appear as follows:
Let's discuss a right triangle. What is the length of the hypotenuse? 5 What is the length of one of the legs? 4 The length of the other leg is 3.0. |
Answer:
While a person's pulse is generally reported in beats per minute, technicians rarely monitor for a full minutes, but instead extrapolate after observing a shorter time. For example, if there were 20 beats in 15 seconds, then the pulse is 80 beats per minute.
Write a program that assists with this calculation, after receiving input about the user's observations. Presume that the pulse should be reported as a (truncated) whole number. A sample session might appear as follows:
How many beats were observed? 20 How many seconds were observed? 18 The pulse is 66 beats per minute. |
Answer:
Write a program that computes the roots of the classic quadratic equation, $Ax^2 + Bx + C = 0$, with the user providing the constants $A$, $B$, and $C$. You may use the quadratic formula which states that the roots are $$\frac{-B + \sqrt{B^2-4AC}}{2A}, \frac{-B - \sqrt{B^2-4AC}}{2A}$$ and you may assume, for simplicity, that the roots are well-defined (although conveniently Python has support for complex roots). A sample session might appear as follows:
Solving quadratic equation A*x*x + B*x + C = 0. What is A? 2 What is B? -5 What is C? -3 One root is 3.0. The other is −0.5. |
Answer: