Questions Uploads

algorithm

I need help with this discussion question. I don’t really understand loops in pyhton 3., so this DQ is very challenging. Please help with the question below.

I need help writing an algorithm using pseudocode for one of the following actions:

  • Converting military time (2400 hours) to standard time (12:00)
  • Counting down to a the following New Year’s eve in days, hours, minutes, and seconds
  • Determining the maximum area of a field you could create with a collection of 15 fence sections, each eight feet in length.
  • Prompting the user to input a set of grades and print the highest value, minimum value, and average.

Post your algorithm to the discussion topic.

  • Explain why you chose the type of control structures and/or loops used in your algorithm (if-else, for, while, etc.).
  • Explain how you might revise the algorithm you designed in Module Two based on any new information you learned here.
 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

CODE

My following code works but I am having one issue and that’s making a new line at a particular section. However, I tried “n” after “Choose an option:” and still doesn’t give me the output I need.

MY CODE

movies = {

   2005:[[‘Munich’, ‘Steven Spielberg’]],

   2006:[[‘The Prestige’, ‘Christopher Nolan’], [‘The Departed’, ‘Martin Scorsese’]],

   2007:[[‘Into the Wild’, ‘Sean Penn’]],

   2008:[[‘The Dark Knight’,’Christopher Nolan’]],

   2009:[[‘Mary and Max’, ‘Adam Elliot’]],

   2010:[[‘The King’s Speech’,’Tom Hooper’]],

   2011:[[‘The Artist’, ‘Michel Hazanavicius’], [‘The Help’, ‘Tate Taylor’]],

   2012:[[‘Argo’, ‘Ben Affleck’]],

   2013:[[’12 Years a Slave’, ‘Steve McQueen’]],

   2014:[[‘Birdman’, ‘Alejandro G. Inarritu’]],

   2015:[[‘Spotlight’,’Tom McCarthy’]],

   2016:[[‘The BFG’, ‘Steven Spielberg’]]

}

# Prompt the user for a year 

year = int(input(‘Enter a year between 2005 and 2016:n’))

if year in movies.keys():

   for movie in movies[year]:

       print(movie[0] +’, ‘+ movie[1])

else:

   print(‘N/A’)

choice =”

while choice != ‘q’:

# Displaying the title(s) and directors(s) from that year

# Display menu

   print(‘nMENU’)

   print(‘Sort by:ny – Yearnd – Directornt – Movie title’)

   print(‘q – Quitn’)

   choice = input(‘Choose an option:’)

   if choice == ‘q’:

       break

   elif choice == ‘y’:

       for year in sorted(movies.keys()):

           print(‘n’ + str(year) + ‘:’)

           for movie in movies[year]:

               print(‘t’ + movie[0] + ‘, ‘ + movie[1])

   elif choice == ‘d’:

       director = []

       for year in movies.keys():

           for movie in movies[year]:

               if movie[1] not in director:

                   director.append(movie[1])

       for d in sorted(director):

           print(‘n’ + d + ‘:’)

           for year in movies.keys():

               for mov in movies[year]:

                   if mov[1] == d:

                       print(‘t’ + mov[0] + ‘, ‘ + str(year))

   elif choice == ‘t’:

       title = []

       for year in movies.keys():

           for movie in movies[year]:

               if movie[0] not in title:

                   title.append(movie[0])

       for t in sorted(title):

           print(‘n’ + t + ‘:’)

           for year in movies.keys():

               for mov in movies[year]:

                   if mov[0] == t:

                       print(‘t’ + mov[1] + ‘, ‘ + str(year))

   else:

       print(‘Error:Invalid choice! Try again.’)

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

zybooks, parsing strings.

Ok guys, I’m having trouble with my code in zybooks, parsing strings.. I have passed 5/ 7 but don’ t know what’s wrong now.. Here’s my code:

while True:

  string1 = input(‘Enter input string: n’)

  if (string1 == ‘q’):

    break;

  if ‘,’ not in string1:

    print(‘Error: No comma in string.’)

  elif ‘ ‘ not in string1:

    print(‘Error: No comma in string.’)

  elif ‘ ‘ in string1:

    print(‘Error: No comma in string.’)

Screen Shot 2018-10-03 at 8.06.58 AM.png

  else:

    first_word, second_word = string1.split(‘,’)

    first_word, second_word = first_word.strip(), second_word.strip()

    print(‘First word:’, first_word)

    print(‘Second word:’, second_word)

    print()

    print() ATTACHMENT PREVIEW

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"

Automobile service invoice (Python 3)

4.10 Program: Automobile service invoice (Python 3)

(4) Extend the program to allow the user to enter a dash (-), which indicates no service. (3 pts) 

Ex:

Select first service: Tire rotation

Select second service: -


Davy's auto shop invoice

Service 1: Tire rotation, $19
Service 2: No service

Total: $19

Here is my code:

# make a dictionary for Davy’s auto shop

davy_auto_services = {

  ‘Oil change’: 35,

  ‘Tire rotation’: 19,

  ‘Car wash’: 7,

  ‘Car wax’: 12

}   

print(“Davy’s auto shop services”)

for key, value in davy_auto_services.items():

  print(key, ‘– $’ + str(value))

print(”)

first_service = input(‘Select first service: n’)

print(”)

second_service = input(‘Select second service: n’)

print(”)

print(“nDavy’s auto shop invoicen”)

#make if statement to loop 

if first_service in davy_auto_services:

  print(‘Service 1:’, first_service + ‘, $’ + str(davy_auto_services[first_service]))

else:

  print(‘Service1: No service’)

#make if statement for sevice 2  

if second_service in davy_auto_services:

  print(‘Service 2:’, second_service + ‘, $’ + str(davy_auto_services[second_service]))     

else: 

  print(‘Service 2: No service’)

print(”)  

total = davy_auto_services.get(first_service) + davy_auto_services.get(second_service)

print(‘Total: $’+ str(total))

#t = 0

#if first_service == “No service”:

  #print(‘Total: $’ + str(t))

#elif second_service not in davy_auto_services:

  #print(‘Total: $’ + str(second_service_total))

Here is the error I get:

Traceback (most recent call last):

File “main.py”, line 31, in <module>

total = davy_auto_services.get(first_service) + davy_auto_services.get(second_service)

TypeError: unsupported operand type(s) for +: ‘int’ and ‘NoneType’

All the other code works fine except for the very last piece. I have no idea how to print only one price..

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"