2017-01-29 1 views
-2

Ich arbeite seit ein paar Tagen daran. Ich habe mir mehrere Tutorials angesehen und in meinem Buch gelesen, ich bin neu in der Programmierung.Python Vielfache von 19

Ich erforderlich, um dieses Programm zu schreiben

Dieses Programm den Benutzer auffordern, sollte ein ganzzahliges Vielfaches von 19 zu gelangen, die größer ist als 200. Dann wird, sollte das Programm die Eingabe und Anzeige eine Antwort auf jede der Analyse vier mögliche Ergebnisse der Analyse. Siehe Beispielläufe unten.

Enter an exact multiple of 19 that is greater than 200 76 
No, 76 is a multiple of 19 but it is not greater than 200 
>>> 
Enter an exact multiple of 19 that is greater than 200 55 
55 is not over 200 and also is not a multiple of 19 
>>> 
Enter an exact multiple of 19 that is greater than 200 222 
222 is over 200 but is not a multiple of 19 
>>> 
Enter an exact multiple of 19 that is greater than 200 380 
Good input. 19 divides into 380 exactly 20 times 

das ist, was ich

#promt user to enter an exact multiple of 19 that is larger than 200 
#assign variable a to user input 
def main() : 
    random = int(input('Enter an exact multiple of 19 that is greater than 200:')) 

    number = random/19 


    if random > 200 : 
     print('Good input 19 divides into', random , 'exactly' , number ,'times') 


    if random % 19 == 0 or random <200: 
     print('is a multiple of 19') 

    else: 
     print('is not a multiple of') 


main() 

bisher haben kann ich das Programm erhalten Sie die Zeile für den Benutzer 380 auszuspucken Eingabe aber ich bin ratlos, soweit wie die aufzuschreiben andere Ausgänge. Hilfe wäre toll !!!

+0

Ah, der fizzbuzz Test ‚ole. (Dies sollte ausreichen, um es herauszufinden, ohne es auf einem Silbertablett zu übergeben) – Enfyve

Antwort

-1

Heres, was ich gearbeitet, obwohl ich denke Im seine Hausaufgaben zu machen ...:

def main(): 
    try: 
     random = int(input('Enter an exact multiple of 19 that is greater than 200:')) 
    except ValueError: 
     print("Not a number") 
     return 

    number = random % 19 #if number==0 it's divisible by 19 

    if random <= 200: #checks to see if the number is less than 200 

     if number == 0: #if the num is divisible by 19 but less than 200 

      print("Enter an exact multiple of 19 that is greater than 200. No, {0} is a multiple of 19 but it is not greater than 200".format(random)) 

     else: #if the num is not divisible by 19 ant it's less than 200 

      print("Enter an exact multiple of 19 that is greater than 200. No, {0} is not over 200 and also is not a multiple of 19".format(random)) 

     return 

    if number != 0: #if the number is over 200 buy not divisible by 19 

     print("Enter an exact multiple of 19 that is greater than 200. No, {0} is over 200 but is not a multiple of 19".format(random)) 
     return 
    #every other possibility: divisible by 19 and over 200 
    print('Good input 19 divides into {0} exactly {1} times'.format(random, random/19)) 

main() 
+3

Bitte erklären Sie dann Code, anstatt nur ihre Hausaufgaben für sie zu machen. – Carcigenicate

+0

@ brittmoe09 mach deine eigenen Hausaufgaben nächstes Mal! Fiel frei, mir ein Häkchen zu geben, um dir zu helfen, wenn ich dein Problem gelöst habe :) – kda

Verwandte Themen