Problema Universidad para mañana AYUDA PLS
Publicado por Ignasi (1 intervención) el 30/09/2019 20:20:04
Buenas gente. Me han puesto un ejercicio de python en la uni y estoy muy encallado, si alguien me pudiese echar una mano seria de gran ayuda. El enunciado es el siguiente:
You have received three € 50 notes from your family for your birthday, and
you decide to place them in 3 different pockets in order to minimize the loss
in case of robbery. Suppose you have p pockets in your pants and jacket,
and you want to know how many ways you can place the notes. Writer a
program that asks the user the numbers of notes and pockets he has and
tells him how many ways he can place those notes in his pockets. Note that
the number of ways of choosing n objects among a set of p is the
combinatorial number:
(p,n)= [ p(p-1)(p-2)...(p-n+1) ] / n!
Notes: 1) Don't use math module. 2) If any of the data is less than 1, the
program must write an error message and stop the execution. 3) If both
data are ≥1 but n > p, the program must report the error and stop the
execution.
Yo llevo escrito lo siguiente:
Si alguien pudiera ayudarme o decirme como seguir seria de gran ayuda
Gracias
You have received three € 50 notes from your family for your birthday, and
you decide to place them in 3 different pockets in order to minimize the loss
in case of robbery. Suppose you have p pockets in your pants and jacket,
and you want to know how many ways you can place the notes. Writer a
program that asks the user the numbers of notes and pockets he has and
tells him how many ways he can place those notes in his pockets. Note that
the number of ways of choosing n objects among a set of p is the
combinatorial number:
(p,n)= [ p(p-1)(p-2)...(p-n+1) ] / n!
Notes: 1) Don't use math module. 2) If any of the data is less than 1, the
program must write an error message and stop the execution. 3) If both
data are ≥1 but n > p, the program must report the error and stop the
execution.
Yo llevo escrito lo siguiente:
1
2
3
4
5
6
7
8
9
10
11
p=int(input('Write the number of pockets that you have:'))
r=int(input('Write the number of notes that you have:'))
if r<1 or p<1:
print('Invalid data, numbers should be =>1, try again please')
if r>p:
print('Invalid data, you can not enter more notes than pockets')
else:
sum=1
for i in range(1,r+1):
sum=sum*i
print(i)
Si alguien pudiera ayudarme o decirme como seguir seria de gran ayuda
Gracias
Valora esta pregunta


0