Python Forum
Question about list and while function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about list and while function
#6
For the more general answer, how about
a = int(input("Enter a: "))
b = int(input("Enter b: "))

answer = [a * b - x for x in range(1,b+1)]
answer.extend([0] * (10-b))

print(answer)
Output:
Enter a: 3 Enter b: 6 [17, 16, 15, 14, 13, 12, 0, 0, 0, 0]
That works for any positive value of b < 10
Reply


Messages In This Thread
RE: Question about list and while function - by adt - Oct-11-2019, 08:45 AM
RE: Question about list and while function - by adt - Oct-11-2019, 12:02 PM
RE: Question about list and while function - by jefsummers - Oct-11-2019, 01:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Question on dir() function Soorya25 1 1,168 Jan-16-2023, 09:33 PM
Last Post: deanhystad
  Function not scriptable: Noob question kaega2 3 1,207 Aug-21-2022, 04:37 PM
Last Post: kaega2
  input function question barryjo 12 2,759 Jan-18-2022, 12:11 AM
Last Post: barryjo
  Question on None function in a machine learning algorithm Livingstone1337 1 2,370 Mar-17-2021, 10:12 PM
Last Post: supuflounder
  Question in python function problem saratha 1 1,475 Jul-08-2020, 04:56 PM
Last Post: jefsummers
  question about python3 print function jamie_01 5 2,687 May-25-2020, 09:58 AM
Last Post: pyzyx3qwerty
  Question about the groupby function new_to_python 7 3,273 Feb-09-2020, 07:52 AM
Last Post: perfringo
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,332 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Question on Join() function sduvvuri 2 2,773 Jun-02-2019, 03:55 PM
Last Post: perfringo
  about List question longmail 2 2,377 Nov-30-2018, 02:08 AM
Last Post: longmail

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020