0

File handling . This code is returning blank lines. Tryingto make a program to make you sleep. Is incomplete btw

x = input() f = open("dhruv.txt", "w+") def wrt(x, n): if x == "": s = str(n) + " Sheep \n" f.write(s) n += 1 print(f.readline()) y = input() wrt(y, n) else: print("Sweet Dreams!!!") wrt(x, 0)

3rd Nov 2019, 5:22 PM
Dhruv Dutta
Dhruv Dutta - avatar
5 Answers
+ 6
Could you explain what you're actually trying to do in a simple word
3rd Nov 2019, 7:27 PM
Mirielle
Mirielle - avatar
0
I am making a program which when is run. Accepts input. Each time the enter key is pressed i want to print the counting of sheeps.and when anything else than the enter key is pressed then the program assumes that the person is asleep. Basically it would be a program to make someone feel sleepy.
3rd Nov 2019, 7:33 PM
Dhruv Dutta
Dhruv Dutta - avatar
0
I actually am a newbie so dont know much about file handling
3rd Nov 2019, 7:34 PM
Dhruv Dutta
Dhruv Dutta - avatar
0
But why do you want to use files in this program .you can do without files.🤔🤔
3rd Nov 2019, 9:02 PM
Preyas
Preyas - avatar
0
I want to use files please.i know it is easier without it.
4th Nov 2019, 1:47 AM
Dhruv Dutta
Dhruv Dutta - avatar