Python Forum
Teacher (thrown in at the deep end - help)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Teacher (thrown in at the deep end - help)
#1
Hi, I'm self learning Python and I need some help (desperately) - I understand that I am double accounting in my simple program (I am adding the total for above 1.57 and also adding for below 1.92). I've spent time attempting to write a nested if statement (if index >=1.57 and <= 1.92) but it isn't working.

Can someone on here help me please?? Oh I'm using version 3 I understand the syntax is different in earlier versions.

total = 0
all_heights = [1.87, 1.48, 1.57, 1.91, 2.01]
for index in all_heights:
    if index >=1.57:
        total = total +1
    if index <= 1.92:
        total = total +1
print ("The total number of qualifying astronauts is ",total)

time.sleep (2)
print ("It's not is it - the program is double counting the total")
Reply


Messages In This Thread
Teacher (thrown in at the deep end - help) - by Mr90 - May-22-2018, 12:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  which exception should be thrown for a sequence of the wrong length? Skaperen 1 851 Jan-06-2023, 04:13 AM
Last Post: deanhystad
  deep learning python Stevedas 1 1,688 Sep-26-2021, 08:32 AM
Last Post: Yoriz
  Pytest API Post call thrown errors pyseeker 4 3,645 Dec-08-2019, 04:53 PM
Last Post: pyseeker
  Invalid argument error thrown. pyseeker 4 8,631 Sep-10-2019, 07:03 PM
Last Post: pyseeker
  convert List of Dicts into a 2 deep Nested Dict rethink 1 3,215 Aug-23-2019, 05:28 PM
Last Post: ichabod801
  pytest fixture in conftest.py thrown error while in the test file runs OzzieOzzum 1 3,986 Jul-31-2018, 12:12 PM
Last Post: OzzieOzzum
  [split] Teacher (thrown in at the deep end - help) Mr90 2 3,022 May-23-2018, 02:04 PM
Last Post: DeaD_EyE
  Parse XML - how to handle deep levels/hierarchy dwill 8 9,454 Apr-17-2018, 04:17 PM
Last Post: dwill
  Exception not thrown in python3 ONEoo7 7 6,138 Apr-09-2017, 01:58 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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