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

(C++) Write a function that takes as an input parameter an integer that will represent the...
(C++) Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number...
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.
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and...
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and use as stack to convert the integer to a its corresponding binary representation. Hint: divide the integer by 2. 2. A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward—assuming that you ignore spaces, punctuation, and case. For example, Race car is a palindrome. So is A man, a...
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 named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "w" replaced with the character "v" My code: function replacement(word){ var str=word; var n=str.replace("w","v"); return n; } Syntax Error: function replacement incorrect on input Not sure how to fix? Can't use a loop for answer
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, 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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT