Skip to content

Commit 684fb5b

Browse files
solution to stars requests library, scores and grades
1 parent cecdd26 commit 684fb5b

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

requests_libray.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Optional Assignment: The Requests Library
2+
Build a simple program that makes use of the requests module.
3+
4+
In addition to including a lot of great features in the language itself,
5+
there are many modules available for install via pip that are a lot of fun
6+
to work with. We talked a little about pip before, so you should have the
7+
basic idea that pip exists so that developers can use code other people have
8+
written.
9+
10+
One of those code libraries is called requests. It allows you to make HTTP
11+
requests from a python file and get back a useful response. This library is
12+
a simple way to make requests to and get responses from a server without
13+
having to set one up yourself. This might remind you a little of using AJAX
14+
to interact with API's like you did in web fundamentals. Give it a try and
15+
get creative with the data you try to get back.
16+
17+
You'll have a much easier time if you install a virtual environment. Find
18+
the instructions to do so here or from external resource.
19+
20+
You'll find the documentation for requests here. We highly recommend trying
21+
the code samples in the Quickstart Guide."""

scores_grades.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''Write a function that generates ten scores between 60 and 100. Each time a score is generated, your function should display what the grade is for a particular score. Here is the grade table:
2+
3+
Score: 60 - 69; Grade - D
4+
Score: 70 - 79; Grade - C
5+
Score: 80 - 89; Grade - B
6+
Score: 90 - 100; Grade - A'''
7+
import random
8+
def final_grade(num):
9+
grade = ""
10+
for i in range(num):
11+
score = random.randint(60,100)
12+
if score >= 60 and score < 70:
13+
grade = "D"
14+
elif score >= 70 and score < 80:
15+
grade = "C"
16+
elif score >= 80 and score < 90:
17+
grade = "B"
18+
elif score >= 90:
19+
grade = "A"
20+
print grade
21+
print "Score: "+ str(score) + "; Your grade is " + grade
22+
23+
final_grade(10)

stars.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Part I
2+
Create a function called draw_stars() that takes a list of numbers
3+
and prints out *."""
4+
5+
def draw_stars(list):
6+
for i in list:
7+
print i*"*"
8+
draw_stars([5,2,3])
9+
10+
"""PART II
11+
Modify the function above. Allow a list containing integers and
12+
strings to be passed to the draw_stars() function. When a string
13+
is passed, instead of displaying *, display the first letter of
14+
the string according to the example below.
15+
You may use the .lower() string method for this part."""
16+
17+
def draw_stars_letters(list):
18+
for item in list:
19+
if isinstance(item, str):
20+
print str.lower(item[0])*len(item)
21+
else:
22+
print item*"*"
23+
24+
draw_stars_letters([5, "Beth", 4, "Mikayla"])

0 commit comments

Comments
 (0)