Question

In: Computer Science

Write a function convert_date that takes an integer as a parameter and returns three integer values...

  1. Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring).

Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py

A sample run for t03.py:

Enter a date in the format MMDDYYYY: 05272017

The output will be:

27/05/2017

The function docstring is as follows:

def convert_date (date_int): """

-------------------------------------------------------

Converts date_int into days, month and year use: day,month,year = convert_date (date_int)

-------------------------------------------------------

Paramaters:

date_int – (int > 0)

returns

day: the day in the month in date_int (int >= 0)

month: the month in date_int (int >=0) year: the years in date_int (int >=0)

------------------------------------------------------- """

  • Test your program with 2 different date values than those given in the example.
  • You may assume that the user will only enter numbers (2 digits for month, 2 digits for days and 4 digits for year)
  • You are not allowed to use any string methods or string indexing.
  • Copy the results to testing.txt.

Solutions

Expert Solution

Program Code Screenshot:

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

def convert_date (date_int):
temp=date_int
c=0
res=""
while temp!=0:#getthe number of digits
temp=temp//10
c+=1
  
if(c==7):#if number of digits is 7 then it means that 0 is present in first place
k=date_int//100000#perform arithmetic operations on the date_int and print the results
print((k%10),end="")
k=date_int//10000
print(k%10,end="")
print("/"+"0",end="")#print the / characters and add 0
print((date_int//1000000),end="")
print("/",end="")
k=date_int%10000
print(k)
else:
k=date_int//10000
print(k%100,end="")
print("/",end="")
k=date_int//1000000#perform arithmetic operations on the date_int and print the results
print((k),end="")
print("/",end="")
k=date_int%10000
print(k)

date=int(input("Enter a date in the format MMDDYYYY:"))#read input of integer type
convert_date(date)#call function

Note:

Please let me know in case of any help needed in the comments section.


Related Solutions

Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Write a function, namely shape(s) that takes a positive integer s as the parameter and draws...
Write a function, namely shape(s) that takes a positive integer s as the parameter and draws a square of length s. The square should be filled by a randomized color. Then write another function, that calls the shape function to draw 4 squares as a 2x2 table. Please answer in python.
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the total sum of the digits in the integers from 1 to that number inclusive. b. Write a program to input an integer n and call the above function in part a if n is positive, else give ‘Value must be Positive’ message. sample: Enter a positive integer: 1000000 The sum of the digits in the number from 1 to 1000000 is 27000001 Enter a...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper...
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper factors/divisors ofn; for example,the sum of factorsof 20= 10+5+4+2 = 21.Note that 1 is nota properfactor of any number.Sample command => output:(display (sumOfFactors20))=> 21Hint: Calla recursivefunction sum_helperfrom sumOfFactorsfunction as follows:(define (sumOfFactors n)(sum_helper n (-n 1)))Here sum_helperfunction takes two parameters: n, d and returns the sum of all factors of n whichare <= d; for e.g. (sum_helper 20 6) returnsall proper factors of 20 which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT