Squared
Complete the Squared programming activity on HumblePython.
Handshakes
One of the great advantages of a small campus like Roanoke College is that it feels like you know everybody on campus. How long would it take for everybody to meet everybody else on campus. Let's find out.
Details
Create a Python program that prints the number of handshakes it would
take for every student in a classroom to shake hands with every other
student. Your program should use input
to get the number
of students in the classroom. This program should use arithmetic
operations to perform the calculations necessary. Use variables where
appropriate, and follow the course's code conventions.
Example
How many students do you have? 28 It would take 378 handshakes for all 28 students to meet each other.
If you are not sure how to compute the number of handshakes, try some simple examples:
-
If there are 2 people, Alice and Bob, the following pairs will need to shake hands:
- Alice and Bob
which is 1 handshake.
-
If there are 3 people, Alice, Bob, and Carol, the following pairs will need to shake hands:
- Alice and Bob
- Alice and Carol
- Bob and Carol
which is 3 handshakes.
-
If there are 4 people, Alice, Bob, Carol, and Dan the following pairs will need to shake hands:
- Alice and Bob
- Alice and Carol
- Alice and Dan
- Bob and Carol
- Bob and Dan
- Carol and Dan
which is 6 handshakes.
Can you figure out how many handshakes there are if there are 5 people? Can you figure out the pattern to finding the number of handshakes for any number of people?
Challenge
The average handshake lasts about 3 seconds. Add code to your program to estimate how long it would take for this many handshakes to occur. Your estimate should be output in days, hours, and minutes.
How many students do you have? 1869 It would take 1745646 number of handshakes for all 1869 students to meet each other. It would take 60 days 14 hours 42 minutes and 18 seconds for everyone to shake hands.
Voyager 1
Voyager 1 is a space probe that was launched by NASA in 1977. It is currently the farthest man-made object from Earth. It is very likely that Voyager 1 is (or will be) the first man-made object to exit the solar system. Currently, Voyager 1 is approximately 21,947,171,607 km from Earth (And yet, Voyager 1 is still closer to the Sun than any other star in our galaxy!). The Voyager 1 communicates with radio waves, which travel at the speed of light, 299,792,458 m/s. At such a great distance, communications take an appreciable amount of time to reach earth.
Details
Create a Python program that prints how long it takes a signal from Voyager 1 to reach the Earth. Since Voyager 1 is constantly moving away from Earth, the program should prompt the user for Voyager's current distance from Earth. The calculations should be performed using Python's arithmetic operations and printed nicely labeled and formatted. Be sure to use variables where appropriate, and follow the course code conventions.
Example
Enter Voyager 1's distance from Earth in kilometers: 20884657351 It takes 69663.7183280975 seconds for a message from Voyager to reach Earth.
- You first need to figure out how many meters Voyager 1 is from Earth. Recall that there are 1000 meters in one kilometer.
- The speed of light above is given in meters per second. So if you divide the distance in meters by the speed of light you will get how many seconds a signal takes to reach Earth.
Challenge
Astronomers recently discovered a potentially habitable planet orbiting the star of one of our solar system's nearest neighbors, Proxima Centauri. Is this new planet close enough that humans could reach it in a lifetime by travelling at the speed of Voyager? Voyager is moving pretty fast, but Proxima Centauri, is also pretty far away, 4.2 light years from Earth. Modify your program to also print how how long it would take Voyager 1 to reach Proxima Centauri at its current velocity. The Voyager 1's velocity is 61,400 km/h.
Example
Enter Voyager 1's distance from Earth in kilometers: 20884657351 It takes 69663.7183280975 seconds for a message from Voyager to reach Earth. It will take 73786.28455464319 years for Voyager to reach Proxima Centauri.