x = 5
print(x)
print("Hello World")
x = "Hello World"
print(x)
x = 5
y = 7.5
print(str(x)+str(y))
x = '23'
y = 5
z = '75.3'
print(int(x))
print(float(z)+int(x))
x = int(input("Please enter your age: "))
print(x,type(x))
x = 4
y = 7
if x > y:
print(x,' is greater than ',y)
elif x < y:
print(x,' is less than ',y)
else:
print(x,' is equal to ',y)
for x in range(10):
print(x)
for x in range(1,10):
print(x)
for x in range(10,1):
print(x)
sum = 0
for x in range(1,11):
sum = sum + x
print(sum)
x = 0
while x < 11:
print(x)
x = x + 1
names = ['John', 'Jim']
for x in names:
print(x)
s = 'John'
for x in s:
print(x)
names.append('Donald')
print(names)
counts = {'A':10, 'B':20, 'C':6, 'A':50}
print(counts)
print(counts['A'])
for x in counts:
print(x,counts[x])
def square(x):
return x*x
square(5)
square(7)
s = "Hello World"
s.count('a')
letters = 'abcdefghijklmnopqrstuvwxyz'
counts = {}
for x in letters:
counts[x] = s.count(x)
def get_counts(fname):
# this function takes the name of a file as input parameter, fname
# it then reads the file into a string variable
# then proceeds to process the string for the count of letters
# answer should be returned in a dictionary of 26 numbers
with open(fname) as f:
data = f.read().lower()
letters = 'abcdefghijklmnopqrstuvwxyz'
#counts = {}
counts = []
for x in letters:
#counts[x] = data.count(x)
counts.append(data.count(x))
return counts
get_counts('ra.txt')
len("abc")
"abc".count('a')
import matplotlib.pyplot as plt
%matplotlib inline
def main():
fall_enrollments = [489, 547, 705, 879, 1075, 1228, 1404, 1550, 1773, 1376]
terms =["F2010","F2011","F2012","F2013","F2014","F2015","F2016","F2017","F2018","F2019"]
xaxis = range(len(terms))
plt.figure(figsize=(16,8))
plt.title("Fall Undergrad Enrollments in Computer Science ")
plt.xlabel("Term")
plt.ylabel("Undergrad Enrollment")
plt.bar(xaxis, fall_enrollments, width=0.5)
plt.xticks(xaxis, terms)
for a,b in zip(xaxis, fall_enrollments):
plt.text(a, b+30, str(b), horizontalalignment='center', verticalalignment='center')
plt.show()
main()