Question

In: Computer Science

#Python 3.7 "Has no attribute" error - def get():     import datetime     d = date_time_obj.date()...

#Python 3.7 "Has no attribute" error -

def get():
    import datetime
    d = date_time_obj.date()
    return(d)

print(a["Date"])
print("3/14/2012".get())

How to write the "get" function (without any imput), to convery the format ""3/14/2012" to the format "2012-03-14", by simply using "3/14/2012".get() ?

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Solution 1 :Without Import datetime

Here a new python program with name "main.py" is created, which contains following code.

main.py :

#function
def get(date):
#split date based on /
date=date.split("/")
#concate elements from list
date=date[2]+"-"+str(0)+date[0]+"-"+date[1]
return date #retun date
#function call to print date
print(get("3/14/2012"))

======================================================

Output : Compile and Run main.py to get the screen as shown below

Screen 1 :main.py

********************

Solution 2 :With import datetime

main.py :

import datetime #import
#pass date and date format
d = datetime.datetime.strptime("3/14/2012", '%m/%d/%Y')
#print date format
print(datetime.date.strftime(d, "%Y-%m-%d"))

===========================

Screen 1 :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

USING PYTHON 3.7: import Student as st import random THRESHOLD = 0.01 tests = 0 passed...
USING PYTHON 3.7: import Student as st import random THRESHOLD = 0.01 tests = 0 passed = 0 def main():    test_get_higher_grade_student()    test_is_grade_above()    test_get_students()    test_get_classlist()    # test_count_above()    # test_get_average_grade()    print("TEST RESULTS:", passed, "/", tests) def test_get_higher_grade_student():    s1a = st.Student("V0002000", 89)    s1b = st.Student("V0002001", 89)    s2 = st.Student("V0002002", 67)    s3 = st.Student("V0002002", 97)    result = get_higher_grade_student(s1a,s1b)    print_test("get_higher_grade_student(s1a,s1b)", result == s1a)    result = get_higher_grade_student(s1a,s2)    print_test("get_higher_grade_student(s1a,s1b)", result == s1a)...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA. To...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path):...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path): """ Retrieve list of students and their expected grade from file, generate a sampled test grade for each student drawn from a Gaussian distribution defined by the student expected grade as mean, and the given standard deviation. If the sample is higher than 100, re-sample. If the sample is lower than 0 or 5 standard deviations below mean, re-sample Write the list of student...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def take_e(n, gen):     return [elem for (i, elem) in enumerate(gen) if i < n] def take_zc(n, gen):     return [elem for (i, elem) in zip(count(), gen) if i < n] FIBONACCI UNBOUNDED: def fibonacci_unbounded():     """     Unbounded Fibonacci numbers generator     """     (a, b) = (0, 1)     while True:         # return a         yield a         (a, b) = (b, a + b) SUPPOSED TO RUN THIS TO ASSIST WITH...
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value pairs of the dictionary as tuples (key, value), reverse sorted by value (highest first) and where multiple keys with the same value appear alphabetically (lowest first).
Python Please Define a class that has one data attribute of type float. The initializer does...
Python Please Define a class that has one data attribute of type float. The initializer does not accept an argument, however, it initializes the data attribute to zero. Include in class the following methods: 1. func that will accept as two arguments. The first argument a value of float type and the second argument if string. The function will perform the following depending on the string argument: a. if string is '+', the first argument will be added to the...
For python... class car:    def __init__(self)          self.tire          self.gas    def truck(self,color)        &nb
For python... class car:    def __init__(self)          self.tire          self.gas    def truck(self,color)               style = color                return    def plane(self,oil)              liquid = self.oil + self.truck(color) For the plane method, I am getting an error that the class does not define __add__ inside init so I cannot use the + operator. How do I go about this.             
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute...
I don't know why I keep getting the following error: AttributeError: 'tuple' object has no attribute 'size' I am using python in Anaconda. import numpy as np def information_gain(x_array, y_array): parent_entropy = entropy(x_array) split_dict = split(y_array) for val in split_dict.values(): freq = val.size / x_array.size child_entropy = entropy([x_array[i] for i in val]) parent_entropy -= child_entropy* freq return parent_entropy x = np.array([0, 1, 0, 1, 0, 1]) y = np.array([0, 1, 0, 1, 1, 1]) print(round(information_gain(x, y), 4)) x = np.array([0,...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT