Skip to content

Commit 054766f

Browse files
committed
Tweaks in the code.
1. Getting data from user 2. Getting file name to store as input from browser 3. If user not interested to give filename, then generate a random number as input and store the file with that name. 4. Followed functional programming.
1 parent caa1b2d commit 054766f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

QR/QR_Encode.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,27 @@
3232

3333
def takeInputFromUser():
3434
givenInput = input("Enter the data : ")
35-
print("As an output, you can expect a QR Code in .png format")
36-
return givenInput
35+
if givenInput:
36+
print("As an output, you can expect a QR Code in .png format")
37+
return givenInput
38+
else:
39+
print("Please input some data")
40+
return None
41+
42+
def getFileNameFromUser():
43+
import random
44+
fileName = input("Enter the filename: ")
45+
return fileName if fileName else str(random.randint(1,100))
3746

3847
def constructQR():
3948
infoFromUser = takeInputFromUser()
40-
fileName = infoFromUser + '.png'
41-
output = pyqrcode.create(infoFromUser)
42-
output.png(fileName, scale=6)
43-
print("done")
44-
49+
if(infoFromUser):
50+
output = pyqrcode.create(infoFromUser)
51+
fileName = getFileNameFromUser()
52+
output.png(fileName + '.png', scale=6)
53+
print(fileName + ".png file got generated and saved in your local.")
54+
else:
55+
takeInputFromUser()
56+
4557
if __name__ == '__main__':
4658
constructQR()

0 commit comments

Comments
 (0)