Answer the question
In order to leave comments, you need to log in
I don't understand how return .?
I wanted to make a characteristic generator for the game, I need to return the characs variable after the chars function, but the program does not display the sum of the three largest numbers from the list.
Вот код :
from random import *
def chars(a):
char = [randint(0,6),randint(0,6),randint(0,6),randint(0,6),randint(0,6)]
c1 = max(char)
char.remove(c1)
c2 = max(char)
char.remove(c2)
c3 = max(char)
char.remove(c3)
c1 = int(c1)
c2 = int(c2)
c3 = int(c3)
print(a)
characs = c1 + c2 + c3
return(characs)
chars(1)
print(characs)
Answer the question
In order to leave comments, you need to log in
import random
def chars():
char = [random.randint(0, 6) for number in range(0)]
max_numbers = []
count = 0
def get_max_numbers(last_index=0):
nonlocal count
count += 1
number = max(char[last_index:])
max_numbers.append(number)
if count < 3:
return get_max_numbers(numbers.index(number, last_index))
return max_numbers
return get_max_numbers()
print("".join(chars(), " "))
from random import *
def chars(a):
char = [randint(0,6),randint(0,6),randint(0,6),randint(0,6),randint(0,6)]
c1 = max(char)
char.remove(c1)
c2 = max(char)
char.remove(c2)
c3 = max(char)
char.remove(c3)
c1 = int(c1)
c2 = int(c2)
c3 = int(c3)
print(a)
characs = c1 + c2 + c3
return(characs)
print(chars())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question