Problem One
Write a function called series_sum() that prompts the user for an non-negative integer n. If the user enters a negative integer the function should return None, otherwise the function should return the sum of the following series for the given integer n. For example, for n = 0, the function should return 1000, for n = 1, the function should return 1001, for n = 2, the function should return 1001.25, for n = 3, the function should return 1001.3611111111111, etc.
>>> series_sum()
Please enter a non-negative integer: -10
>>> series_sum()
Please enter a non-negative integer: 0
1000
>>> series_sum()
Please enter a non-negative integer: 5
1001.463611111111
Problem Two
Hint: Think of how slicing and reversing of strings can help with this problem.
You want to send a note to your friend in class, and because you want to be respectful in class, you don’t want to
whip out your phone and send a text or an email (or any other digital communication). Instead, you choose to go old school and write it out on a piece of paper and pass it along to your friend. The problem is, you don’t want anyone else to read the note as they pass it along. Luckily, your friend and you have come up with an encryption system so that nobody else can understand your message. Here’s how it works: you write out your message backwards (so, Hello, world becomes dlrow ,olleH). But you don’t stop there, because that’s too easy to crack – anyone can figure that out!)
Now that you’ve written it backwards, you start on either side of the string and bring the characters together. So, the first and the last characters become the first and the second character in the encrypted string, and the second and the second last characters become the third and the fourth characters in the string, and so on. Thus, Hello, world ultimately becomes dHlerlolwo. And 0123456789 becomes 9081726354.
(Notice how all punctuations, special characters, spaces, etc are all treated the same)
Write a function called encrypt, that has one parameter s where s is a string and encrypt returns a string which is
the encrypted version of s.
Fun fact in cryptography, s is called “clear text” and the encrypted version you return is called “cipher text”
>>> encrypt(“Hello, world”)
‘dHlerlolwo ,’
>>>> encrypt(“1234”)
‘4132’
>>> encrypt(“12345”)
‘51423’
>>> encrypt(“1”)
‘1’
>>> encrypt(“123”)
‘312’
>>> encrypt(“12”)
’21’
>>> encrypt(“Secret Message”)
‘eSgeacsrseetM ‘
>>> encrypt(“,’4’r”)
“r,”4″
Problem Three
Write a function named month_apart that accepts four integer parameters representing two calendar dates. Each date consists of a month (1 through 12) and a day (1 through the number of days in that month [28-31]). Assume that all dates occur during the same year. The method returns whether the dates are at least a month apart. For example, the following dates are all considered to be at least a month apart from 9/19 (September 19): 2/14, 7/25, 8/2, 8/19, 10/19, 10/20, and 11/5. The following dates are NOT at least a month apart from 9/19: 9/20, 9/28, 10/1, 10/15, and 10/18. Note that the first date could come before or after (or be the same as) the second date. Assume that all parameter values passed are valid.
Sample calls:
month_apart( 6, 14, 9, 21) should return True, because June 14 is at least a month before September 21
month_apart( 4, 5, 5, 15) should return True, because April 5 is at least a month before May 15
month_apart( 4, 15, 5, 15) should return True, because April 15 is at least a month before May 15
month_apart( 4, 16, 5, 15) should return False, because April 16 isn’t at least a month apart from May 15
month_apart( 6, 14, 6, 8) should return False, because June 14 isn’t at least a month apart from June 8
month_apart( 7, 7, 6, 8) should return False, because July 7 isn’t at least a month apart from June 8
month_apart( 7, 8, 6, 8) should return True, because July 8 is at least a month after June 8
month_apart(10, 14, 7, 15) should return True, because Oct 14 is at least a month after July 15
Problem Four
Write a function named count_even_digits that accepts two integers as parameters and returns the number of even-valued digits in the first number. An even-valued digit is either 0, 2, 4, 6, or 8. The second value represents how many digits the number has. The second value is guaranteed to match the number of digits in the first number.
For example, the number 8546587 has four even digits (the two 8s, the 4, and the 6),
so the call count_even_digits(8346387, 7) should return 4.
You may assume that the values passed to your function are non-negative.
All+Files
APA
CLICK HERE FOR FURTHER ASSISTANCE ON THIS ASSIGNMENT
The post Write a function called series_sum() that prompts the user for an non-negative integer n. If the user enters a negative integer the function should return None, otherwise the function should return the sum of the following series for the given integer n. For example, for n = 0, the function should return 1000, for n = 1, the function should return 1001, for n = 2, the function should return 1001.25, for n = 3, the function should return 1001.3611111111111, etc. >>> series_sum() Please enter a non-negative integer: -10 >>> series_sum() Please enter a non-negative integer: 0 1000 >>> series_sum() Please enter a non-negative integer: 5 1001.463611111111 appeared first on Apax Researchers.