<jupyter_start><jupyter_text>--- **Chapter 2 - Variables, expressions and statements**Name: **Ajeet**Collaborators: NoneTime spent:---  Question 1After the following statements, what are the values of x and y?x = 15y = xx = 22  Answer When y = x at the second statement, the value of y became 15. At 3rd statement, the value of x chanaged to 22, but the value of y remained at 15.So, x = 22, y =15 --- Question 2Take the sentence: All is well. Store each word in a separate variable, then print out the sentence on one line using print.Answer:<jupyter_code>a = "All"
b = "is"
c = "well"
print(a,b,c)<jupyter_output>All is well<jupyter_text>Note that running  print(a, " ", b, " ", c)  will put extra space in the output<jupyter_code>print(a, " ", b, " ", c)<jupyter_output>All   is   well<jupyter_text>Question 3Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6. Answer<jupyter_code>print(6 * (1 - 2))<jupyter_output>-6<jupyter_text>Question 4The formula for computing the final amount if one is earning compound interest is given on Wikipedia asWrite a Python program that assigns the principal amount of $10000 to variable P, assign to n the value 12, and assign to r the interest rate of 8%. Then have the program prompt the user for the number of years t that the money will be compounded for. Calculate and print the final amount after t years. AnswerA quick note: This image won't appear in GitHub if you use the code `` Use slash at the end ``[Issue](https://github.com/jupyter/notebook/issues/3278issuecomment-395038360)<jupyter_code>p = 10000
n = 12
r = 0.08  # 8%

number_of_years_t = int(input("Enter the number of years t that the money will be compounded for: "))

final_amount = p*(1 + r/n)**(n*number_of_years_t)

print("The final amount after",number_of_years_t, "years is", final_amount)<jupyter_output>Enter the number of years t that the money will be compounded for:  12<jupyter_text>--- Question 5Find the ouput0/77/08/77/80//77//08//77//80 % 77 % 0 Answer<jupyter_code>print(0/7)
print(7/0)
print(8/7)

print(7/8)
print(0//7)
print(7//0)
print(8//7)

print(7//8)
print(0 % 7)
print(7 % 0) # this will give error<jupyter_output><empty_output><jupyter_text>Question 6You look at the clock and it is exactly 2pm. You set an alarm to go off in 51 hours. At what time does the alarm go off? (Hint: you could count on your fingers, but this is not what we’re after. If you are tempted to count on your fingers, change the 51 to 5100.)Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and ask for the number of hours to wait. Your program should output what the time will be on the clock when the alarm goes off. Answer<jupyter_code>current_time = float(input("Enter current time in hours 0 - 23, 0 means 12 AM: "))
# float as time may be 2.30 PM, so user should enter the correct time in both hours and minutes
number_of_hours_to_wait = int(input("Enter number of hours to wait: "))

alarm_goes_off_hours = current_time + number_of_hours_to_wait

time_alarm_goes_off_hours = alarm_goes_off_hours%24 # using the modulus operator- this will give the remainder

print("Alarm goes off at", time_alarm_goes_off_hours)<jupyter_output>Enter current time in hours 0 - 23, 0 means 12 AM:  5
Enter number of hours to wait:  12<jupyter_text>--- Question 7:Based on Question, find out what's wrong with this program`current_time = input("What is the current time (in hours 0 - 23)?")``wait_time = input("How many hours do you want to wait")``print(current_time)``print(wait_time)``final_time = current_time + wait_time``print(final_time)`  Answer<jupyter_code>current_time = input("What is the current time (in hours 0 - 23)?")

wait_time = input("How many hours do you want to wait")

print(current_time)

print(wait_time)

final_time = current_time + wait_time

print(final_time)<jupyter_output>What is the current time (in hours 0 - 23)? 5
How many hours do you want to wait 12
{'fraction_non_alphanumeric': 0.09152627608750315, 'fraction_numerical': 0.03721398038722655, 'mean_word_length': 4.682857142857143, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '291686', 'license': 'MIT', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1259, 'n_words': 540, 'path': 'chapter_2_variables_expressions_and_statements.ipynb', 'repo_name': 'ajeet001/how-to-think-like-a-computer-scientist-learning-with-python-3', 'size': '3977'}