Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While Loop
#1
Hi there,

I have three different csv-files (chicago.csv, new_yourk.csv and washington.csv) I want to write a code where I will ask a user to choose one of the city from this files:
This is ma code:
import time
import pandas as pd
import numpy as np

CITY_DATA = { 'chicago': 'chicago.csv',
              'new york city': 'new_york_city.csv',
              'washington': 'washington.csv' }

def get_filters():
print('Hello! Let\'s explore some US bikeshare data!')
    print('Would you like to see data for Chicago, New York, or Washington')
    # get user input for city (chicago, new york city, washington). 
Cities = ('Chicago', 'New York', 'Washington')
while city in cities:
    print city
But my while loop doesn't work. could somebody please help Rolleyes

J
Reply
#2
you have

Cities = ('Chicago', 'New York', 'Washington')

and then

while city in cities:

try

while city in Cities:
Reply
#3
Where do you get the input?
'Cities' in the loop condition starts with small 'c'. It's not the same object.
If the city is in Cities this will cause an infinite loop.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
So, why do you have both CITY_DATA and Cities?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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