Python Forum
Validate a List and print YES or NO
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validate a List and print YES or NO
#6
(Nov-15-2016, 02:21 AM)Aoleone# Wrote: Hi Guys, I'll be grateful for a bit more illustration. Just started learning python. I tried below but not so good.
A=[]
N= input("Enter some numbers: ")
for i in range(n):
  D = int(input("Enter a single number"))
  A.append(D)
    print(C)

Why all the single character variable names? Normally, single-character variables are a big flag to anyone reading your code that says "this value doesn't really matter, and it isn't used for anything important. Feel free to ignore." Wouldn't it make more sense to give them labels you can remember, like "items" or "length"?  Also, what's "C", and why is it indented?

N should be passed through int(), otherwise range() will fail since it can't give a range over a string.  You're doing a good job building the list, so next (AFTER the for loop) you should use something like an if statement to check if what you want is inside the list.

Unless you just want to copy/paste some code.  Then feel free to use this :)
print("YES" if set(range(1, 4)).issubset(int(input("Single number please: ")) for i in range(int(input("How many items? ")))) else "NO")
Reply


Messages In This Thread
Validate a List and print YES or NO - by Aoleone# - Nov-15-2016, 01:02 AM
RE: Validate a List and print YES or NO - by nilamo - Nov-16-2016, 03:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do you get Python to print just one value in a list? 357mag 3 1,061 May-17-2023, 09:52 PM
Last Post: rob101
  validate large json file with millions of records in batches herobpv 3 1,329 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Create SQL connection function and validate mg24 1 985 Sep-30-2022, 07:45 PM
Last Post: deanhystad
Sad how to validate user input from database johnconar 3 2,000 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  Print List to Terminal DaveG 2 1,485 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Print max numbers in a list jimmoriarty 1 2,184 Sep-25-2020, 07:29 AM
Last Post: DPaul
  Print variable values from a list of variables xnightwingx 3 2,679 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Unable to Validate csv blanck data and write in csv prashant18 0 1,565 Jul-25-2020, 12:08 PM
Last Post: prashant18
  Print the number of items in a list on ubuntu terminal buttercup 2 1,971 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  taking input doesnt print as list bntayfur 2 2,158 Jun-04-2020, 02:48 AM
Last Post: bntayfur

Forum Jump:

User Panel Messages

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