#05-1###################################################
"""Write a program that counts how many of the squares
of the numbers from 1 to 100 end in a 1."""

##count = 0
##for i in range(1,100):
##    if (i*i % 10 == 1):
##        count += 1        
##        print(i,"*",i," =",i*i)        
##print("count =",count)


#05-2####################################################
"""Write a program that counts how many of the squares
of the numbers from 1 to 100 end in a 4 and how many end
in a 9."""

##count4s = 0
##count9s = 0
##for i in range(1,100):
##    if (i*i % 10 == 4):
##        count4s += 1        
##        print(i,"*",i,"=",i*i)    
##for i in range(1,100):
##    if (i*i % 10 == 9):
##        count9s += 1        
##        print(i,"*",i,"=",i*i) 
##print("count4s =",count4s)
##print("count9s =",count9s)


#05-3######################################################
"""Write a program that asks the user to enter a value n,
and then computes (1 + 1/2 + 1/3 + ... + 1/n) - ln(n).
The ln function is log in the math module."""

##import math
##result = 0
##n = eval(input("Enter value of n: "))
##for i in range(1,n+1):
##    result += 1/i   
##result -= math.log(n)
##print(result)


#05-4######################################################
"""Write a program to compute the sum:
1 - 2 + 3 - 4 + ... + 1999 - 2000."""

##result = 0
##sign = -1
##for i in range(1,2001):
##    result += i * (-1)*sign
##    sign *= -1
##print("result =", result)
    

#05-5######################################################
"""  Write a program that asks the user to enter a number
and prints the sum of the divisors of that number. The sum
of the divisors of a number is an important function in
number theory."""


##x = int(input("Enter X:"))
##a = []
##for i in range(1,x):
##    if x % i == 0:
##        a.append(i)
##print("Divisors =",*a,x)
##print("Sum of the divisors =",sum(a)+x)



#05-6######################################################
"""A number is called a perfect number if it is equal to
the sum of all of its divisors, not including the number
itself. For instance, 6 is a perfect number because the
divisors of 6 are 1, 2, 3, 6 and 6 = 1 + 2 + 3. As another
example, 28 is a perfect number because its divisors are
1, 2, 4, 7, 14, 28 and 28 = 1 + 2 + 4 + 7 + 14. However,
15 is not a perfect number because its divisors are 1, 3,
5, 15 and 15 != 1 + 3 + 5. Write a program that finds all
four of the perfect numbers that are less than 10000."""

##def perfectNum(x):
##  for num in range(1,x):
##   divisors = []
##   results = 0
##   perfect_num=[]
##   for i in range(1,num):
##       if num % i == 0:
##           divisors.append(i)
##           results = sum(divisors)
##   if results == num:
##      perfect_num.append(results)
##      print("Divisors:",*divisors,"\nSum of the divisors",results,"\nPerfect Num:",*perfect_num)
##print(perfectNum(10000))


#05-7######################################################
"""An integer is called squarefree if it is not divisible
by any perfect squares other than 1. For instance, 42 is
squarefree because its divisors are 1, 2, 3, 6, 7, 21, and
42, and none of those numbers (except 1) is a perfect
square. On the other hand, 45 is not squarefree because it
is divisible by 9, which is a perfect square. Write a
program that asks the user for an integer and tells them
if it is squarefree or not."""

##from math import sqrt
##def squareFree(num):
##    #for num in range(1,n):
##        divisors = []
##        results = 0
##        square_num = []
##        for i in range(1, num):
##            if num % i == 0:
##                divisors.append(i)
##                results = sum(divisors)
##        for j in range(len(divisors)):
##            while  divisors[j] != 1  and divisors[j] % sqrt(divisors[j]) == 0  :
##                #sq =num / divisors[j] != 0
##                if num % divisors[j] == 0:
##                   square_num.append(divisors[j])
##                   return(num,"SQUARES FOUND,Its Squares are",square_num,divisors)
##                else :
##                   return (num,"Is not a square",divisors)
####When No ssquare is found none is returned .##This is a bug im still to fix
##print(squareFree(49))

#05-8######################################################
"""Write a program that swaps the values of three variables
a, b, and c, so that a gets the value of b, b gets the
value of c, and c gets the value of a.
a=1, b=2, c=3
a <== b, b <== c, c <== a
a=2, b=3, c=1
"""

##a,b,c = input("Enter 3 values: ").split()
####holda = a
####holdb = b
####holdc = c
####a = holdb
####b = holdc
####c = holda
##hold = a
##hold2 = a
##a = b
##hold = b
##b = c
##hold = c
##c = hold2
##print("a =",a,"b =",b,"c =",c)


#05-9######################################################
"""
Write a program to count how many integers from 1 to 1000
are not perfect squares, perfect cubes, or perfect
fifth powers.

"""

##from math import sqrt
##count = 0
##for num in range(1, 1001):
##    if sqrt(num) % 1 != 0 and (num**(1/3)) % 1 != 0 and (num**(1/5)) % 1 != 0:
##        count+=1
##print(f'There are {count} numbers that are not perfect squares, cubes, or fifths.')


#05-10######################################################
"""
Ask the user to enter 10 test scores. Write a program to do
the following:
(a) Print out the highest and lowest scores.
(b) Print out the average of the scores.
(c) Print out the second largest score.
(d) If any of the scores is greater than 100, then after
all the scores have been entered, print a message warning
the user that a value over 100 has been entered.
(e) Drop the two lowest scores and print out the average of the rest of them.
"""

##from statistics import mean
##mylist = []
##for i in range(10):
##  score = eval(input(f'Enter Test Score {i+1}: '))
##  while score < 0 or score > 100:
##    score = eval(input(f'Invalid. Enter Test Score {i+1}: '))
##    continue
##  mylist.append(score)  
##mylist.sort(reverse = True)
##max_score = max(mylist)
##min_score = min(mylist)
##max2_score = mylist[1]
##ave_score = mean(mylist)
##ave2_score = mean(mylist[:-2])
##print(f'The maximum score was {max_score} and the minimum score was {min_score}.')
##print(f'The 2nd largest score was {max2_score}.')
##print(f'The average was {ave_score}. The average score with the two lowaest scores dropped is {ave2_score}.')

#05-11######################################################
"""
Write a program that computes the factorial of a number.
The factorial, n!, of a number n is the product of all the
integers between 1 and n, including n. For instance,
5! = 1 · 2 · 3 · 4 · 5 = 120. [Hint: Try using a
multiplicative equivalent of the summing technique.

"""


##def factorial(x):
##  for i in range(1, x):
##    x *= i
##  print(f'Factorial is {x}.')
##num = eval(input('Enter a number: '))
##factorial(num)

#05-12######################################################
"""
Write a program that asks the user to guess a random number
between 1 and 10. If they guess right, they get 10 points
added to their score, and they lose 1 point for an
incorrect guess. Give the user five numbers to guess and
print their score after all the guessing is done.
"""

##from random import randint
##score = 0
##for i in range(5):
##  comp_guess = randint(1, 10)
##  user_guess = eval(input('Enter guess between 1 and 10: '))
##  while user_guess < 0 or user_guess > 10:
##    user_guess = eval(input('Invalid. Enter guess between 1 and 10: '))
##    continue
##  if user_guess == comp_guess:
##    score += 10
##    print(f'You guessed right! Your score is {score}.')
##  else:
##    score -= 1
##    print(f'Wrong. Computer guessed {comp_guess}. You guessed {user_guess}.')
##print(f'\nAfter 5 rounds, your total score is {score}.')

#05-13######################################################   


#05-14######################################################    
"""
This exercise is about the well-known Monty Hall problem.
In the problem, you are a contestant on a game show. The
host, Monty Hall, shows you three doors. Behind one of
those doors is a prize, and behind the other two doors are
goats. You pick a door. Monty Hall, who knows behind which
door the prize lies, then opens up one of the doors that
doesn’t contain the prize. There are now two doors left,
and Monty gives you the opportunity to change your choice.
Should you keep the same door, change doors, or does it not
matter?

Write a program that simulates playing this game 10000
times and calculates what percentage of the time you would
win if you switch and what percentage of the time you
would win by not switching.
"""

##from random import randint, choice
##count = 0
##for i in range(1000):
##  user_guess = randint(1, 3)
##  prize = randint(1, 3)
##  if prize == 1:
##    doors = [1, randint(2,3)]
##    if user_guess not in doors:
##      user_guess = choice(doors)
##      if user_guess == prize:
##        count += 1
##    else:
##      if user_guess == prize:
##        count += 1
##  if prize == 2:
##    doors = [2, randint(1,3)]
##    if user_guess not in doors:
##      user_guess = choice(doors)
##      if user_guess == prize:
##        count += 1
##    else:
##      if user_guess == prize:
##        count += 1
##  if prize == 3:
##    doors = [3, randint(2,3)]
##    if user_guess not in doors:
##      user_guess = choice(doors)
##      if user_guess == prize:
##        count += 1
##    else:
##      if user_guess == prize:
##        count += 1
##percentage = round((count/1000) * 100, 2)
##print(f'User chose the correct door {count} amount of times out of 1000. The percentage is {percentage}%.')
