Zählen gerade und ungerade zahlen und die Summen (python)

Ich habe eine harte Zeit mit meinen Hausaufgaben ich denke, ich bin nah an eine Antwort, aber ich bin stecken wie jetzt. Im Grunde sind wir eigentlich-Eingang ein high-integer für die reichen, eine niedrige ganze Zahl für den Bereich und geben Sie dann eine Zahl ein, um herauszufinden, die ein Vielfaches für diese Zahl. Während ich war in der Lage, die vielfachen von was auch immer Nummer, die ich eingegeben, sind wir dann eigentlich auch zählen, gerade und ungerade zahlen in die Multiplikatoren gedruckt und insgesamt Sie:

hier mein code bisher:

 def main():
        high = int(input('Enter the high integer for the range: ')) # Enter the high integer
        low = int(input('Enter the low integer for the range: '))   # Enter the lower integer
        num = int(input('Enter the integer for the multiples: '))   # Enter integer to find multiples

        def show_multiples():
                # Find the multiples of integer
                # and print them on same line
                for x in range(high, low, -1):
                        if (x % num) == 0:
                                print(x, end=' ')

                def isEven(x):
                        count = 0
                        total = 0
                        for count in range():
                                if (x % 2) == 0:
                                        count = count + 1
                                else:
                                        count = count + 1


                        print(count, 'even numbers total to')
                        print(count, 'odd numbers total to')
                isEven(x) 
        show_multiples()
main() 

Bin ich in der Nähe eine Antwort oder bin ich Weg?
Neue python dies ist mein erstes mal mit es für die Klasse.

EDIT:

Here are the instructions for the homework:

Part 1: Write a program named multiples1.py that generates all multiples of a specified
integer within a specified consecutive range of integers. The main function in the program
should prompt the user to enter the upper and lower integers of the range and the integer
for which multiples will be found. A function named show_multiples should take these three
integers as arguments and use a repetition structure to display (on same line separated by
a space) the multiples in descending order. The show_multiples function is called inside
main. For this program, assume that the user enters range values for which multiples do exist.
SAMPLE RUN
Enter the high integer for the range 100
Enter the low integer for the range 20
Enter the integer for the multiples 15
90 75 60 45 30

Part 2: Make a copy of multiples1.py named multiples2.py. Modify the show_multiples
function so it both counts and totals the even multiples and the odd multiples. The
show_multiples function also prints the counts and sums. See sample run.
SAMPLE RUN
Enter the high integer for the range 100
Enter the low integer for the range 20
Enter the integer for the multiples 15
90 75 60 45 30 
3 even numbers total to 180
2 odd numbers total to 120

Part 3: Make another copy of multiples1.py named multiples3.py. Modify the show_multiples
function so that it creates and returns a list consisting of all of the multiples (even
and odd). The show_multiples function should print only "List was created", not the
multiples. Create another function named show_list that takes the list as its sole
argument. The show_list function should output the size of the list, display all of the
list elements, and output the average of the list accurate to two decimal places. See
sample run.
SAMPLE RUN
Enter the high integer for the range 100
Enter the low integer for the range 20
Enter the integer for the multiples 15
List was created
The list has 5 elements.
90 75 60 45 30
Average of multiples is 60.00
  • Nun, es hängt, wenn Sie Sie ausführen - Sie bekommen die Antworten, die Sie erwarten?
  • Sieht aus wie Sie mit der gleichen Anzahl für gerade und ungerade zahlen?
  • Ja, ich bin mit der gleichen Anzahl für gerade und ungerade zahlen. Soll ich tun, eine andere Anzahl für jeden? & ja, wenn ich es laufen lasse, druckt es die vielfachen der Zahl I input. Aber nach, dass es nicht funktioniert.
  • wenn Sie die gleiche Anzahl, dann sind Sie zählen die Summe von geraden und ungeraden zahlen, nicht getrennt zählt.
  • Ok ich behoben, und machte eine even_count und ein odd_count. Aber es immer noch nicht, weil die for-loop-Bereich in der Funktion ISTGERADE
InformationsquelleAutor Brandon | 2014-09-02
Schreibe einen Kommentar