[Tutor] Problem

khalil zakaria Zemmoura zemmoura.khalil at gmail.com
Sun Aug 28 16:34:15 EDT 2016


Can you please rewrite the python code using proper indentation, since, as
you know, indentation matters in Python

Le 28 août 2016 18:40, "shahan khan" <shahankhan0 at gmail.com> a écrit :

Hello
I'm teching myself Python using MIT opencourse ware. I'm a beginner and
have some what knowledge of c and c++. I'm using Python version

Here is the problem:
McDiophantine: Selling McNuggets
In mathematics, a Diophantine equation (named for Diophantus of Alexandria,
a third century Greek mathematician) is a polynomial equation where the
variables can only take on integer values. Although you may not realize it,
you have seen Diophantine equations before: one of the most famous
Diophantine equations is:
xn + yn= zn.
For n=2, there are infinitely many solutions (values for x, y and z) called
the Pythagorean triples, e.g. 32 + 42 = 52. For larger values of n,
Fermat’s famous “last theorem” states that there do not exist any positive
integer solutions for x, y and z that satisfy this equation. For centuries,
mathematicians have studied different Diophantine equations; besides
Fermat’s last theorem, some famous ones include Pell’s equation, and the
Erdos-Strauss conjecture. For more information on this intriguing branch of
mathematics, you may find the Wikipedia article of interest.
We are not certain that McDonald’s knows about Diophantine equations
(actually we doubt that they do), but they use them! McDonald’s sells
Chicken McNuggets in packages of 6, 9 or 20 McNuggets. Thus, it is
possible, for example, to buy exactly 15 McNuggets (with one package of 6
and a second package of 9), but it is not possible to buy exactly 16
nuggets, since no non-negative integer combination of 6’s, 9’s and 20’s
adds up to 16. To determine if it is possible to buy exactly n McNuggets,
one has to solve a Diophantine equation: find non-negative integer values
of a, b, and c, such that
6a + 9b + 20c = n.
Problem 1.
Show that it is possible to buy exactly 50, 51, 52, 53, 54, and 55
McNuggets, by finding solutions to the Diophantine equation. You can solve
this in your head, using paper and pencil, or writing a program. However
you chose to solve this problem, list the combinations of 6, 9 and 20 packs
of McNuggets you need to buy in order to get each of the exact amounts.
Given that it is possible to buy sets of 50, 51, 52, 53, 54 or 55 McNuggets
by combinations of 6, 9 and 20 packs, show that it is possible to buy 56,
57,…, 65 McNuggets. In other words, show how, given solutions for 50-55,
one can derive solutions for 56-65.
Theorem: If it is possible to buy x, x+1,…, x+5 sets of McNuggets, for some
x, then it is possible to buy any number of McNuggets >= x, given that
McNuggets come in 6, 9 and 20 packs.

Here is my code:
 for a in range(1,10):
for b in range(1,5):
for c in range(1,5):
mc=(6*a)+(9*b)+(20*c)
if mc==50:
print a,b,c
else:
print a,b,c
a=+1
b=b+1
c=c+1
and this is the output:
1 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
2 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
3 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
4 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
5 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
6 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
7 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
8 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4
9 1 1
1 2 2
1 3 3
1 4 4
1 2 1
1 3 2
1 4 3
1 5 4
1 3 1
1 4 2
1 5 3
1 6 4
1 4 1
1 5 2
1 6 3
1 7 4.

Can someone please tell me whats wrong with my code?. I'm using for loops
to give possible valutes to a,b and c and then using the equation
(6*a)+(9*b)+(20*c) to determine possible values for a,b and c for
satisfying the equation.
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list