-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY_2.py
More file actions
149 lines (82 loc) · 2.4 KB
/
Copy pathDAY_2.py
File metadata and controls
149 lines (82 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# coding: utf-8
# Understanding Data Types and how to manipulate Strings
# In[2]:
# using len function
x = "12345"
len(x) # working well with Strings
# In[4]:
# it doesn't work with integers
y = 1243
len(y)
# In[5]:
# It generates a TYPE_ERROR -
# # DATA TYPES
# In[10]:
# Strings - iterables
text = "Hello"
print("Hello"[4]) # getting a single character out of the string - Subscripting
# In[15]:
# Integers - whole numbers
x = 123,456,789
y = 123_456_789
x, y
# In[17]:
# Float - with a decimal point
x = 123.890
# In[21]:
# Boolean - two possible values
x = True
y = False
(x, y)
# In[26]:
num_char = len(input("what's your name?"))
print("Your name has " + num_char + " characters") # -> TYPE_ERROR - can't concatanete strings with number
# In[46]:
# Solution
# 1 - Use Type Conversion
num_char = len(input("what's your name?"))
print("Your name has " + str(num_char) + " characters")
# 2 - Use F-String
num_char = len(input("what's your name?"))
print(f"Your name has {num_char} characters")
# 3 - Simply putting things together
num_char = len(input("what's your name?"))
print("Your name has " , num_char , " characters")
# In[34]:
# Round
x = 8/3
int(x), round(x)
# int simply drops decimal part, round intelligently completes the number
# In[36]:
# or using
8 // 3 # similar to int(x)
# In[44]:
# Increment Operator
x = 4
x += 1
x = x + 1
# Both are same
# In[51]:
score = 0
height = 1.8
winning = True
print("Your score is ", score, "Your height is ", height, "Your winning chances are " , winning)
# Instead of doing this a lot of manual labor - use FString
print(f"Your score is {score} Your height is {height} Your winning chances are {winning}")
# # YOUR LIFE IN WEEKS
# In[59]:
# This challenge calculates how many weeks you're left with if you're lucky enough to live 60 years...
# Let's start by giving your age !!
age = int(input("Write your age in numbers. "))
# It would be converted to days , weeks and months
print(f"You have lived {age * 365} days, {age * 52} weeks and {age * 12} months")
total = 60
remaining = total - age
print(f"You are left with {remaining * 365} days, {remaining * 52} weeks and {remaining * 12} months")
# # DAY_2 Project
# Here's the link to the project of day-2 Python 100 days of code challenge.
# You can access it on replit!.
#
# https://replit.com/@AqsaAshfaq07/tipcalculator?v=1
# # The End :)