Jovian
⭐️
Sign In
In [1]:
s=[]
for i in range(4):
    f = int(input("enter a number"))
    s.append(f)

for j in s:
    if j%2 == 0:
        print(j," is even")
    else:
        print(j," is odd")
enter a number12 enter a number19 enter a number17 enter a number24 12 is even 19 is odd 17 is odd 24 is even
In [2]:
str = "this is a string"
In [3]:
str
Out[3]:
'this is a string'
In [5]:
str1 = '''4
3
2
4'''
In [6]:
str1
Out[6]:
'4\n3\n2\n4'
In [17]:
str1 = str1.split("\n")
In [8]:
int(str1)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-8-96962c76182f> in <module> ----> 1 int(str1) ValueError: invalid literal for int() with base 10: '4\n3\n2\n4'
In [12]:
str1[0] = int(str1[0])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-12-928e950e6467> in <module> ----> 1 str1[0] = int(str1[0]) TypeError: 'str' object does not support item assignment
In [19]:
str2 = []
In [20]:
for i in str1:
    str2.append(int(i))
print(str2)
[4, 3, 2, 4]
In [21]:
d = "Akash"
In [22]:
d = "Abhi"
In [23]:
d[0]
Out[23]:
'A'
In [24]:
d = '''a
b
h
i'''
In [25]:
d[0]
Out[25]:
'a'
In [26]:
c=10
In [28]:
print("the value of c is {}".format(c))
the value of c is 10
In [31]:
print("{x} is the item purchased and {x} is the price".format(x="Football"))
Football is the item purchased and Football is the price
In [32]:
str2
Out[32]:
[4, 3, 2, 4]
In [33]:
sum(str2)
Out[33]:
13
In [35]:
g = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
In [36]:
g[1][1]
Out[36]:
6
In [40]:
for i in g:
    row_max = i[0]
    for j in i:
        if j>row_max:
            row_max = j
    print("{} is the largest value".format(row_max))
4 is the largest value 8 is the largest value 12 is the largest value 16 is the largest value
In [41]:
p = [7,6,5,4]
In [42]:
q = (7,8,9,0)
In [43]:
r={1,2,3,4}
In [44]:
p[0] = 1
In [45]:
p
Out[45]:
[1, 6, 5, 4]
In [46]:
q[0]=1
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-46-861bc10886b5> in <module> ----> 1 q[0]=1 TypeError: 'tuple' object does not support item assignment
In [47]:
{1,2,1,2,3,4,5,3,2,1}
Out[47]:
{1, 2, 3, 4, 5}
In [51]:
w = {"name":"Akash","age":20}
In [49]:
w["name"]
Out[49]:
'Akash'
In [50]:
t = {"0":[[0,4,3],[2,3,4]],"1":[{"1":{"1":78}}]}
In [56]:
t['1'][0]['1']['1']
Out[56]:
78
In [59]:
t['0'][1][1]
Out[59]:
3
In [60]:
data = [{"name":"Akash","age":20},{"name":"Gautam","age":28},{"name":"Abhi","age":25}]
In [64]:
temp = data[0]
for i in data:
    if temp["age"]<i["age"]:
        temp = i

print("{} is the oldest guy".format(temp["name"]))
    
Gautam is the oldest guy
In [ ]:
if a==0:
    print("a is 0")
elif a>10:
    print("a is greater than 10")
else:
    print("a is not 0")
In [1]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: