-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_of_intro_to_python_i.py
132 lines (92 loc) · 3.59 KB
/
copy_of_intro_to_python_i.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# -*- coding: utf-8 -*-
"""Copy of Intro_to_Python_I.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/12iiD-WoO43zIGrCMnuWQW-W_gTu_WRD0
# **Lab 1 - Introduction to Python programming I**
Enter your code in the spaces provided. Do not change any of the variable names or function names that are already provided for you. In places where we specify the name of the return value, make sure that your code produces the a value with the correct name.
"""
# Do not edit this cell.
LabID="Lab1"
try:
from graderHelp import ISGRADEPLOT
except ImportError:
ISGRADEPLOT = True
"""**Enter your name, section number, and BYU NetID**"""
# Enter your first and last names in between the quotation marks.
first_name="Madison"
last_name="Wozniak"
# Enter your Math 215 section number in between the quotation marks.
section_number="001"
# Enter your BYU NetID in between the quotation marks. NOT YOUR BYU ID NUMBER!
BYUNetID="856491976"
"""**Problem 1**"""
my_first_var= (118+11*2)/(9-2) # Replace the value of 0 with the required expression from Problem 1.
"""**Problem 2**"""
def arithmetic2(i):
w=((i+2)*3)-5
return w # Put your return value here. Your shouldn't need to add any more lines of code to this function.
"""**Problem 3**"""
def triple(y):
x=3*y
return x# Put your return value here.
def avg(x,y):
z=(x+y)/2
return z# Put your return value here.
def combine(x,y):
z=avg(x,triple(y))
# Put your code here. Remember that this function should call both of the functions triple(y) and avg(x,y) from above.
return z # Put your return value here.
"""**Problem 4**"""
c=[1,2,3,4,5,6,6,6,9]
def first(c):
z=c[0]
# Put your code here.
return z
first(c) # Put your return value here.
def first_last(c):
z=c[0]
x=c[-1]
# Put your code here.
return z,x
first_last(c)# Put your return values here. Remember a function can return two values (you will format your return statement as "return value1, value2").
def middle(c):
z=c[1:-1]
# Put your code here.
return z
middle(c)# Put your return value here.
"""**Problem 5**"""
def swap(c):
new_list=c.copy() # This creates a copy of the list c, which is called new_list. Your function should work with this list instead of the list c which is passed to the function.
dummyList=new_list[0]
new_list[0]=new_list[-1]
new_list[-1]=dummyList
return new_list
swap(c) # Put your return value here.
"""**Problem 6**"""
def absolute_value(x):
if x<0:
x=x-2*x
return x
else:
return x
absolute_value(40)
"""**Problem 7**"""
def indicator(lower,upper,n):
if n>=lower and n<=upper:
return 1
else:
return 0
"""**Problem 8**"""
def trunc_max(x,y):
if x>= 0 or y>=0:
if x>=y:
return x
else:
return y
else:
return 0
"""**STOP! BEFORE YOU SUBMIT THIS LAB:** Go to the "Runtime" menu at the top of this page, and select "Restart and run all". If any of the cells produce error messages, you will either need to fix the error(s) or delete the code that is causing the error(s). Then use "Restart and run all" again to see if there are any new errors. Repeat this until no new error messages show up. """
"""**You are not ready to submit until you are able to select "Restart and run all" without any new error messages showing up. Your code will not be able to be graded if there are any error messages.**
To submit your lab for grading you must first download it to your compute as .py file. In the "File" menu select "Download .py". The resulting file can then be uploaded to http://www.math.byu.edu:30000 for grading.
"""