HELP with syntax

python

#1

I need help with this problem? I seem to have the data arrays printing but it doesn’t come out correctly. I am using Python 3.0.

These are two data arrays, representing
#total time spent on assignments in a course weekly, and numeric grades of students.
#However, I have intentionally added error to the numbers.
#Using a random uniform distribution, add or subtract a value between
#0 and 4 to hours spent, and 0 to 10 to each numeric grade.
#Plot the regression line for your simulated data (one time only).

import warnings
warnings.filterwarnings(‘ignore’)

time_spent_in_course=[5, 7, 8, 10, 16, 5, 5, 7, 8, 20]
numeric_grade = [80, 85, 85, 90, 90, 90, 75, 75, 85, 75]

import random
random_hour = random.uniform(0,4)
print(‘Time spent will be subtracted by:’)
print(random_hour)


#2

What do you want to ignore?


#3

Ignore errors. I don’t think the code is necessary, but this is what i have. This should be clean code? It came out with data but I am not 100% if it was correct data.

mport warnings
warnings.filterwarnings(‘ignore’)

time_spent_in_course=[5, 7, 8, 10, 16, 5, 5, 7, 8, 20]
numeric_grade = [80, 85, 85, 90, 90, 90, 75, 75, 85, 75]

import random
random_hour = random.uniform(0,4)
print(‘Time spent will be subtracted by:’)
print(random_hour)
#The value will be subtracted from the random value generated from the list. In this case, it will be the from the time spent in the course

updated_time_spent_in_course = [x - random_hour for x in time_spent_in_course]

print(‘The new times spent will be:’)
print (updated_time_spent_in_course)

random_grade = random.uniform(0,10)
print(‘Grade will be subtracted by:’)
print(random_grade)
#This will subtracting this randomly generated value from the list grade.

updated_numeric_grade = [x - random_grade for x in numeric_grade]

print(‘The new grades will be:’)
print (updated_numeric_grade)

import pandas
all_data = pandas.DataFrame({‘Time Spent in Course’:updated_time_spent_in_course, ‘Grade’:updated_numeric_grade})

matplotlib.pyplot.figure()
seaborn.regplot(x=‘Time Spent in Course’, y=‘Grade’, data = all_data)


#4

May we assume the goal here is to generate a random float?

>>> import random
>>> round(random.uniform(0, 4), 2)
2.35    # GPA format
>>> round(random.uniform(0, 4), 3)
2.353   # secondary sigdig in further calculations
>>> 

Aside

Of course this is staged. But the above is to be expected output, which is demonstrated. (QED?)


#5

I modified the code completely. I guess to provide more context

I was provided two data arrays, and I have to find

#total time spent on assignments in a course weekly, and numeric grades of students.
#However, I have intentionally added error to the numbers.
#Using a random uniform distribution, add or subtract a value between
#0 and 4 to hours spent, and 0 to 10 to each numeric grade.
#Plot the regression line for your simulated data (one time only).

My code is as follows.

time_spent_in_course=[5, 7, 8, 10, 16, 5, 5, 7, 8, 20]
numeric_grade = [80, 85, 85, 90, 90, 90, 75, 75, 85, 75]

import numpy as np

counter = 1
list_of_timevariation = list()
list_of_gradevariation = list()
while counter <= 10:
    list_of_timevariation.append(random.uniform(-4,4))
    list_of_gradevariation.append(random.uniform(-10,10))
    counter = counter + 1
    
timevariationarray = np.array(list_of_timevariation)
gradevariationarray = np.array(list_of_gradevariation)
    
time_final = np.add(time_spent_in_course, timevariationarray)
grade_final = np.add(numeric_grade, gradevariationarray)


print("Time Spent in Course:")
print(time_final)

print("Numeric Grade:")
print(grade_final)


all_data = pandas.DataFrame({'Time Spent in Course':time_final, 'Numeric Grade':grade_final})
    
matplotlib.pyplot.figure()
seaborn.regplot(x='Time Spent in Course', y='Numeric Grade', data = all_data

The syntax was correct, but not it comes up with an error.


#6

Hopefully, somebody familiar with data science will pipe in. I am not set up to test this code but I did check the syntax…

The very last line is missing a closing paren, ).

Where is your code importing,

random
pandas
matplotlib -> pyplot
seaborn

?


#7

I managed to figure it out on my own! The syntax just had to trace back and I had to import some things. Thanks for the help