8 Replies - 527 Views - Last Post: 25 January 2016 - 01:10 PM Rate Topic: -----

#1 dylansheils0241  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 15

Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 08:10 AM

global file

file = open('data.txt', 'r+')

c = input('How is the weather outside? Like good, fair, bad, horrifying, cloudy, sunny, windy, rain: ')
if 'good' in c:
    if '0' in file:
        print('Seems like a good day for you')
        d = input('By the way I never caught your name please enter: ')
        file.write('%s\n' % d)
        file.write('greatday_weather\n')
    elif '1' in file:
        d = input('Please enter your name: ')
        print('Well, the day is good')
        file.write('%s\n' % d)
elif 'fair' in c:
    if '0' in file:
        print('Well, as you can agree this is a fair day!')
        file.write('fair_day_good_weather\n')
    elif '1' in file:
        print('Looking at the glass at half full, it is not raining')
        file.write('fair_bad_day\n')
elif 'bad' in c:
    if '0' in file:
        print('Sorry... However the day seems to be nice according to yourself')
        file.write('badweather_good_day')
    elif '1' in file:
        print('Well, I am sorry this has happened to you')
        file.write('bad_weather_in_additon_to_day')
elif 'horrifying' in c:
    if '0' in file:
        print('Sorry... However the day seems to be nice according to yourself')
        file.write('badweather_good_day')
    elif '1' in file:
        print('Well, I am sorry this has happened to you')
        file.write('bad_weather_in_additon_to_day')
elif 'rain' in c:
    if '0' in file:
        print('Sorry... However the day seems to be nice according to yourself')
        file.write('badweather_good_day')
    elif '1' in file:
        print('Well, I am sorry this has happened to you')
        file.write('bad_weather_in_additon_to_day')
elif 'windy' in c:
    if '0' in file:
        print('Sorry... However the day seems to be nice according to yourself')
        file.write('badweather_good_day')
    elif '1' in file:
        print('Well, I am sorry this has happened to you')
        file.write('bad_weather_in_additon_to_day')
elif 'cloudy' in c:
    if '0' in file:
        print('Sorry... However the day seems to be nice according to yourself')
        file.write('badweather_good_day')
    elif '1' in file:
        print('Well, I am sorry this has happened to you')
        file.write('bad_weather_in_additon_to_day')
elif 'sunny' in c:
    if '0' in file:
        print('This is a wonderfull day might even be perfect!')
        file.write('greatweather_gooddy')
    elif '1' in file:
        print('At least the weather is good, get out and get some of those rayz...')
        file.write('greatweather_badday')




# No errors but it does not do this part. I did make a data.txt file. Thanks for looking at it and have a nice day! :)/>

This post has been edited by modi123_1: 25 January 2016 - 08:11 AM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Help do not know what is wrong! PLEASE!

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13946
  • View blog
  • Posts: 55,682
  • Joined: 12-June 08

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 08:13 AM

Please explain what the issue is.

Also, in the future, try for more descriptive titles.
Was This Post Helpful? 0
  • +
  • -

#3 dylansheils0241  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 15

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 08:17 AM

Sorry, the problem is when I run my whole program it neglects the block of code inside of it. I appreciate you advice, and help. Next time I will do your suggestions.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Beginner
  • member icon


Reputation: 11018
  • View blog
  • Posts: 18,804
  • Joined: 19-March 11

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 08:19 AM

Also, please explain exactly what you're trying to achieve here.

View Postdylansheils0241, on 25 January 2016 - 10:17 AM, said:

Sorry, the problem is when I run my whole program it neglects the block of code inside of it



More specific than that. What is it that you're expecting to have happen that isn't happening?
Was This Post Helpful? 0
  • +
  • -

#5 dylansheils0241  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 15

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 08:23 AM

Okay so what I am trying to do is take the user's input of c then see if it has or is a string using an if statement then it print a response and saves something to a file. Then I will use that info later in the program. I am a beginner and if you could help that would be great. And as a side note thank you all for viewing and commenting. :)
Was This Post Helpful? 0
  • +
  • -

#6 DK3250  Icon User is offline

  • Pythonian
  • member icon

Reputation: 395
  • View blog
  • Posts: 1,265
  • Joined: 27-December 13

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 11:12 AM

You have two if statements repeating:
if '0' in file:
..
elif '1' in file;
..

But file is
file = open('data.txt', 'r+')

You will never find that '0' or '1' is in file. Thus no output.
Try run a
print(file)
in line 4...
Was This Post Helpful? 1
  • +
  • -

#7 dylansheils0241  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 15

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 12:56 PM

Good point, I did file.read() and before that I did file.write('1') it returns nothing like you predicted. So my follow up question has to be what could I do so python would look in the file and if a certain string is in said file then it responses appropriately.
Thanks for helping me I was stuck.

This post has been edited by andrewsw: 25 January 2016 - 01:03 PM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#8 dylansheils0241  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 15

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 01:08 PM

Looked it up on the googlez and found an answer. Just do if 'hello' in open('example.txt').read(): something. Thanks for reviewing and helping me guys. I appreciate it! :)
Was This Post Helpful? 0
  • +
  • -

#9 jon.kiparsky  Icon User is offline

  • Beginner
  • member icon


Reputation: 11018
  • View blog
  • Posts: 18,804
  • Joined: 19-March 11

Re: Help do not know what is wrong! PLEASE!

Posted 25 January 2016 - 01:10 PM

What I'm wondering about is why you're doing all of this file in/out in the first place...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1