Skip to content

Commit 3c3ba67

Browse files
authored
Add files via upload
1 parent 7f3efc8 commit 3c3ba67

10 files changed

+263
-0
lines changed

Functions/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .initRestaurants import initRestaurants
2+
from .menu import menu
3+
from .promptAction import promptAction
4+
from .implementAction import implementAction
5+
from .displayRestaurants import displayRestaurants
6+
from .displayRestRatings import displayRestRatings
7+
from .validIndex import validIndex
8+
from .addRating import addRating
9+
from .displayIndexRating import displayIndexRating

Functions/addRating.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from Classes import Rating
2+
import string
3+
4+
def addRating(restaurant):
5+
"""This function gets all the required information from the user in order to create a new rating for a specified restaurant. The function takes in one argument, which is mutable, when it is called, an object of type Restaurant. The function then appends the new rating to the restaurant's already existing ratings."""
6+
7+
#declaration and initialization of variables
8+
user = comment = ""
9+
ratingValue = 0
10+
flag = False
11+
rating = Rating()
12+
13+
#prompting the user to enter his or her name
14+
print("Please enter in the user...")
15+
#while loop which runs until the user enters a valid name entry
16+
while flag == False:
17+
user = input("Please enter in a string with at least one character and at most ten characters: ")
18+
#conditional statement checking if user's name is valid
19+
if len(user) > 0 and len(user) <= 10:
20+
flag = True
21+
22+
#prompting the user to enter his or her rating value for the restaurant
23+
print("Please enter in the rating...")
24+
#while loop which runs until the user enters a valid rating index entry
25+
while flag == True:
26+
ratingValue = input("Please enter in a rating value between one and five: ")
27+
#conditional statement which checks if user's input contains only integers and input's maximum length is one
28+
if ratingValue not in string.digits or len(ratingValue) != 1:
29+
continue
30+
ratingValue = int(ratingValue)
31+
#conditional statement which checks if the user's input is valid
32+
if ratingValue > 0 and ratingValue < 6:
33+
flag = False
34+
35+
#prompting the user to enter his or her comment for the rating
36+
print("Please enter in the comment...")
37+
#while loop which runs until the user enters a valid comment entry
38+
while flag == False:
39+
comment = input("Please enter in a string with at least one character and at most five hundred characters: ")
40+
#conditional statement which checks if the input's comment is valid
41+
if len(comment) > 0 and len(comment) <= 500:
42+
flag = True
43+
44+
#creating new instance of rating and adding rating to restaurant
45+
rating = Rating(user, ratingValue, comment)
46+
restaurant.setRatings(rating)
47+
48+
print("Rating successfully added\n")

Functions/displayIndexRating.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def displayIndexRating(restaurant, index):
2+
"""This function will the rating at the specified index within the specified restaurant's list. This function also takes in one mutable, argument which is stored into restaurant, and one immutable argument which is stored into index."""
3+
4+
#printing rating at specified restaurant and index to user
5+
print("User: " + restaurant.getRatings(index).getUser())
6+
print("Rating Value: " + str(restaurant.getRatings(index).getRatingValue()))
7+
print("Comment: " + restaurant.getRatings(index).getComment() + "\n")

Functions/displayRestRatings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def displayRestRatings(restaurant):
2+
"""This function prints each rating for a specified restaurant. This function takes in one mutable argument, which is an object of type Restaurant."""
3+
4+
print("\nRatings for " + restaurant.name)
5+
#for loop which iterates over each restaurant rating
6+
for i in range(0, restaurant.getRatingsSize()):
7+
#printing each restaurant rating to the user
8+
print("Rating Index: " + str(i))
9+
print("User: " + restaurant.getRatings(i).getUser())
10+
print("Rating Value: " + str(restaurant.getRatings(i).getRatingValue()))
11+
print("Comment: " + restaurant.getRatings(i).getComment())
12+
print("******************\n")

Functions/displayRestaurants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def displayRestaurants(restaurants):
2+
"""This function will print every restaurant that is in the system, along with some additional information about the restaurant. This function also takes in a singular, mutable, argument from the function's call."""
3+
4+
print("\nDisplay restaurants...")
5+
#for loop which iterates over each index of the list of restaurants
6+
for i in range(len(restaurants)):
7+
#printing information about each restaurant to the user
8+
print("Restaurant Index: " + str(i))
9+
print("Restaurant Name: " + restaurants[i].getName())
10+
print("Website: " + restaurants[i].getWebsite())
11+
print("******************\n")

Functions/implementAction.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from Functions import displayRestaurants, displayRestRatings, validIndex, addRating, displayIndexRating
2+
3+
def implementAction(restaurants, action):
4+
"""This function determines who the flow of the program will run based on the user's menu selection. This function takes in two arguments into its parameter list: restaurants and action."""
5+
6+
#declaration and initialization of variables
7+
index = 0
8+
ratingIndex = 0
9+
10+
#conditional statement which checks if user's input is either "a" or "A"
11+
if action == "a" or action == "A":
12+
#calling displayRestaurants function to display all the restaurants in the system
13+
displayRestaurants.displayRestaurants(restaurants)
14+
15+
#conditional statement which checks if user's input is either "b" or "B"
16+
elif action == "b" or action == "B":
17+
print("\nDisplay all ratings for a restaurant...")
18+
#getting a valid restaurant index from user by calling validIndex function
19+
index = validIndex.validIndex(restaurants, "1")
20+
#calling displayRestaurants function to display all the restaurant's in the system
21+
displayRestRatings.displayRestRatings(restaurants[index])
22+
23+
#conditional statement which checks if user's input is either "c" or "C"
24+
elif action == "c" or action == "C":
25+
print("\nAdd a rating to a restaurant...")
26+
#getting a valid restaurant index from user by calling validIndex function
27+
index = validIndex.validIndex(restaurants, "1")
28+
#calling addRating function to add a rating to the specified restaurant
29+
addRating.addRating(restaurants[index])
30+
31+
#conditional statement which checks if user's input is either "d" or "D"
32+
elif action == "d" or action == "D":
33+
print()
34+
#getting a valid restaurant index from user by calling validIndex function
35+
index = validIndex.validIndex(restaurants, "1")
36+
#getting a valid rating index from the user by calling validIndex function
37+
ratingIndex = validIndex.validIndex(restaurants[index], "2")
38+
#calling displayIndexRating function to display a rating at the specified restaurant and at the specified index
39+
displayIndexRating.displayIndexRating(restaurants[index], ratingIndex)

Functions/initRestaurants.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from Classes import Rating, Restaurant
2+
3+
def initRestaurants(restaurants):
4+
"""This function initializes five restaurants and appends each instance of the class Restaurant to a mutable list. This mutable list is the function's only argument that is passed to the parameter."""
5+
6+
#declaration and initialization of variables
7+
ratings = []
8+
rating = Rating()
9+
restaurant = Restaurant()
10+
11+
#creating two instances of Rating and appending them to a list of ratings
12+
rating = Rating("Sally Jo", 4, "I love their vanilla ice cream!")
13+
ratings.append(rating)
14+
rating = Rating("Mike Smith", 2, "Their chocolate ice cream is just okay.")
15+
ratings.append(rating)
16+
#creating an instance of Restaurant and appending it to a list of restaurants
17+
restaurant = Restaurant("Val's Ice Cream", ratings, "www.val'sIceCream.com")
18+
restaurants.append(restaurant)
19+
#clearing list of ratings
20+
ratings.clear()
21+
22+
#creating two instances of Rating and appending them to a list of ratings
23+
rating = Rating("Selena Gomez", 1, "No hamburgers. Only chicken.")
24+
ratings.append(rating)
25+
rating = Rating("Cher", 5, "The fries are amazing!")
26+
ratings.append(rating)
27+
#creating an instance of Restaurant and appending it to a list of restaurants
28+
restaurant = Restaurant("Chick-fil-a", ratings, "www.chick-fil-a.com")
29+
restaurants.append(restaurant)
30+
#clearing list of ratings
31+
ratings.clear()
32+
33+
#creating two instances of Rating and appending them to a list of ratings
34+
rating = Rating("Demi Lovato", 2, "The food was too greasy!")
35+
ratings.append(rating)
36+
rating = Rating("Halsey", 4, "I love their milkshakes.")
37+
ratings.append(rating)
38+
#creating an instance of Restaurant and appending it to a list of restaurants
39+
restaurant = Restaurant("McDonald's", ratings, "www.mcDonald's.com")
40+
restaurants.append(restaurant)
41+
#clearing list of ratings
42+
ratings.clear()
43+
44+
#creating two instances of Rating and appending them to a list of ratings
45+
rating = Rating("Trippie Redd", 4, "I love their salads.")
46+
ratings.append(rating)
47+
rating = Rating("YNW Melly", 3, "Their food was decent.")
48+
ratings.append(rating)
49+
#creating an instance of Restaurant and appending it to a list of restaurants
50+
restaurant = Restaurant("Applebee's", ratings, "www.applebee's.com")
51+
restaurants.append(restaurant)
52+
#clearing list of ratings
53+
ratings.clear()
54+
55+
#creating two instances of Rating and appending them to a list of ratings
56+
rating = Rating("Wendy Williams", 4, "They have the same name as me")
57+
ratings.append(rating)
58+
rating = Rating("Lil Durk", 2, "The wait was so long for food.")
59+
ratings.append(rating)
60+
#creating an instance of Restaurant and appending it to a list of restaurants
61+
restaurant = Restaurant("Wendy's", ratings, "www.wendy's.com")
62+
restaurants.append(restaurant)
63+
#clearing list of ratings
64+
ratings.clear()

Functions/menu.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def menu():
2+
"""This function prints the following menu whenever the function is called."""
3+
4+
#printing menu to the screen
5+
print("Please select from the following options...")
6+
print(" A - Display Restaurants")
7+
print(" B - Display all ratings for a restaurant")
8+
print(" C - Add a rating to a restaurant")
9+
print(" D - Display a rating for a restaurant")
10+
print(" Q - Quit")

Functions/promptAction.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from Functions import menu
2+
3+
def promptAction():
4+
"""This function gets the user's input for his or her desired menu selection. This function then returns a string call userInput which is the user's input."""
5+
6+
#declaration and initialization of variable
7+
userInput = ""
8+
9+
#calling menu function, printing menu to screen, and getting user's input
10+
menu()
11+
userInput = input("What would you like to do?\n")
12+
13+
#returning user's input
14+
return userInput

Functions/validIndex.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import string
2+
3+
def validIndex(restaurant, guide):
4+
"""This function gets a valid restaurant index from the user. When the user is prompted to enter a restaurant index, the index needs to be checked to ensure a restaurant at that index exists. This function takes in one mutable argument, which is an instance of Restaurant. The function then returns the user's valid restaurant index as a variable of type integer."""
5+
6+
#declaration and initialization of variables
7+
x = nonNumCounter = 0
8+
flag = False
9+
index = ""
10+
11+
#conditional statement checking if guide is equal to one
12+
if guide == "1":
13+
x = len(restaurant)
14+
#conditional statement checking if guide does not equal one
15+
else:
16+
x = restaurant.getRatingsSize()
17+
18+
#while loop which runs until the user enters a valid restaurant index
19+
while flag == False:
20+
#conditional statement checking if guide is equal to one
21+
if guide == "1":
22+
#getting index input from user
23+
index = input("Please enter in a Restaurant Index: ")
24+
#conditional statement checking if guide does not equal one
25+
else:
26+
#getting index input from user
27+
index = input("Please enter in a Rating Index: ")
28+
29+
#conditional statement which checks if the length of the user's input is greater than zero
30+
if len(index) > 0:
31+
#for loop which iterates over each character of the user's input
32+
for i in range(0, len(index)):
33+
#conditional statement which checks if each character is a digit
34+
if index[i] not in string.digits:
35+
nonNumCounter += 1
36+
37+
#conditional statement checking whether the number of non-digit characters is equal to zero
38+
if nonNumCounter == 0:
39+
index = int(index)
40+
#conditional statement which checks if the user's input is valid
41+
if index < x:
42+
flag = True
43+
44+
#conditional statement checking whether the number of non-digit characters is not equal to zero
45+
else:
46+
nonNumCounter = 0
47+
48+
#returning the valid restaurant index as an integer
49+
return index

0 commit comments

Comments
 (0)