+ 2

Someone help me out dunno why this code isn't working

num1= int("a") num2= int("b") num3= int("c") num = num1+num2+num3 num=20 if num1 != num2 : if num1!= num3 : if num2 != num3: print (num1,num2,num3)

10th Mar 2017, 2:26 PM
egbekun karena
egbekun karena - avatar
15 odpowiedzi
+ 3
Check my codes. I wrote one to get you 3 random numbers = 20.
11th Mar 2017, 2:08 PM
LordHill
LordHill - avatar
+ 1
thanks very much actually a friend o f mine gave me the task find 6 random number s that it's sum is equal 20 without repeating the number twice
11th Mar 2017, 2:25 PM
egbekun karena
egbekun karena - avatar
+ 1
Ok.. To be fair, your friend thinks he is funny. you can't get to 20 with 6 numbers with no repeats. well, you can, but 1 of them has to be a 0 and one has to be a 10. 1+2+3+4+10+0 = 20 .. but that's it as far as I can tell
11th Mar 2017, 2:47 PM
LordHill
LordHill - avatar
0
of corse this can never work take care about types of variables
10th Mar 2017, 2:30 PM
DAHMANI MOHAMED ELAMINE
DAHMANI MOHAMED ELAMINE - avatar
0
num=int("a") .. you are naming a variable. then your casting it as an integer.. but then you are putting a letter in " " marks which tells python it is a str num=5 num="a" python knows when you are putting an int or a str. no need to declare it, only to change it. for instance num=5 is an int num=str(num) .. num is now a str
10th Mar 2017, 5:36 PM
LordHill
LordHill - avatar
0
but even if I remove "" it still give error
11th Mar 2017, 1:14 PM
egbekun karena
egbekun karena - avatar
0
becaus a is not int and b
11th Mar 2017, 1:17 PM
DAHMANI MOHAMED ELAMINE
DAHMANI MOHAMED ELAMINE - avatar
0
I want to tell python to pick 3 random numbers that it's sum is equals 20
11th Mar 2017, 1:21 PM
egbekun karena
egbekun karena - avatar
0
num1=1 num2=4 num3=8 num = num1+num2+num3 num=20 if num1 != num2: if num1!= num3: if num2 != num3: print (num1,num2,num3)
11th Mar 2017, 1:35 PM
LordHill
LordHill - avatar
0
this is a sumpl of random generation import random for i in range(3): value = random.randint(1, 20) print("Random ",i," ",value)
11th Mar 2017, 2:09 PM
DAHMANI MOHAMED ELAMINE
DAHMANI MOHAMED ELAMINE - avatar
0
No Dahmani.. I don't think he wants 3 random numbers between 1 and 20. he wants 3 random numbers that = 20 total
11th Mar 2017, 2:20 PM
LordHill
LordHill - avatar
0
so I decided to act smart using python buteven after getting the solution for 3 random digit Ii cant solve that of six
11th Mar 2017, 2:27 PM
egbekun karena
egbekun karena - avatar
0
I guess that the answer coz I've been on the issue and still no positive outcome
11th Mar 2017, 8:09 PM
egbekun karena
egbekun karena - avatar
0
since you are trying to work it out, even tho there is only 1 outcome if the goal is no doubles (unless I'm wrong, it has been known to happen).. here is what I came up with. import random def getnumbers(): running=True mylist=[] while running==True: num=random.randint(0,4) if num in mylist: continue else: mylist.append(num) if len(mylist) < 5: continue else: running=False sum=0 for i in mylist: sum=sum+i finalnumber=20-sum mylist.append(finalnumber) return mylist print(getnumbers())
11th Mar 2017, 9:06 PM
LordHill
LordHill - avatar
- 1
from your previous code I coined out this from random import randint def getnums(): num1=randint(1,9) num2=randint(1,9) num3=randint(1,9) num4=randint(1,9) num5=randint(1,9) num6=randint(1,9) sum=num1+num2+num3+num4+num5+num6 sum=20 print(num1) print(num2) print(num3) print(num4) print(num5) print(num6) print(sum) getnums()
11th Mar 2017, 8:10 PM
egbekun karena
egbekun karena - avatar