Skip to main content

· One min read
Kaustubh Kulkarni

Code >

file.py
import numpy as np
arr = [[114, 117, 19, 33, 44],
[15, 6, 27, 8, 19],
[23, 2, 54, 1, 24,]]
print("Sum of array : ", np.sum(arr))
print("Sum of arr(float32) : ", np.sum(arr, dtype = np.float32))

Output >

Output
Sum of array :  506
Sum of arr(float32) : 506.0

· One min read
Kaustubh Kulkarni

Code >

file.py
import numpy as np
import pandas as pd
matrix = [(100, 63, 47),
(11, 103, 117),
(49, 36, 55),
(75,24, 34),
(89, 21, 44)
]
panda_max = pd.DataFrame(matrix, index = list('symca'), columns = list('psk'))
maxValues = panda_max.max()
print(maxValues)

Output >

Output
100
103
117

· One min read
Kaustubh Kulkarni

You are given a Juice class, which has name and capacity properties. You need to complete the code to enable and adding of two Juice objects, resulting in a new Juice object with the combined capacity and names of the two juices being added.

For example, if you add an Orange juice with 1.0 capacity and an Apple juice with 2.5 capacity, the resulting juice should have: name: Orange&Apple capacity: 3.5

The names have been combined using an & symbol.

Use the a** method to define a custom behavior for the + operator and return the resulting object.

Program Answer >

file.py
class Juice:
def __init__(self, name, capacity):
self.name = name
self.capacity = capacity
def __add__(self, other):
return self.name + "&" + other.name + " (" + str(self.capacity + other.capacity) + "L)"
a = Juice('Orange', 1.5)
b = Juice('Apple', 2.0)
result = a + b
print(result)
Output
input
No input
Your Output
Orange&Apple (3.5L)
Expected Output
Orange&Apple (3.5L)

· 2 min read
Kaustubh Kulkarni

In this tutorial we will see Making Free Medium Blog,

First visit medium.com,

& if you don't have a medium account, Create an account, Once the account is created login into your account, Once you are logged in to your medium account click on the profile picture in the top right and select the Write Story option. Making Free Medium Blog

Once you click on write story you will see option to write post, In Story title add title for your blog post & below write content you can also import images, videos etc easily.

See Screenshot below Making Free Medium Blog

After writing story click on Publish button in top right corner, Medium will ask for more post details, Let's see

Story Preview : In story preview you have to put featured image for your story, it will be shown in top of your post and also show as thumbnail when you share post on social media paltforms.

Making Free Medium Blog

Once your story is published you will get a confirmation dialog box about that your story is published,

If this was your first post medium will ask you to complete your profile, Making Free Medium Blog

You will be asked to provide full name, your bio and profile photo, add those details, if don't want to add now just click on continue. ( you can always change these setting later)

Now in next step we can claim url Making Free Medium Blog

You can claim as you want, after that click on claim URL, Make sure that once you claim URL, do not change URL, that will affect your site ranking

That's it , done, Keep in mind You can not run ads here, they have there own partner program please read about it in profile section.

If you want to read more about Advantages and disadvantages of medium you can read here

· One min read
Kaustubh Kulkarni

Adding Words

You need to write a function that takes multiple words as its argument and returns a concatenated version of those words separated by dashes (-). The function should be able to take a varying number of words as the argument.

Sample input

this is great

Sample Output

this-is-great Recall, using

addWords.py

def concatenate(*args):
print('-'.join(args))


print(concatenate("I", "love", "Python", "!"))

· One min read
Kaustubh Kulkarni
  • First thread to print the square of a number entered by user,
  • Second thread to print the cube of a number and show the result. Use start and join operations.
file.py
from _thread import *
import threading as thread
def sqr(name,num):
print(name+" : ",num*num)
def cube(name,num):
print(name+" : ",num*num*num)
try:
no=int(input("enter number : "))
thread.start_new_thread( sqr, ("\nThread - 1: Square:", no ) )
thread.start_new_thread( cube, ("\nThread - 2: Cube :", no ) )
#join()
numTuple = ['1', '2', '3', '4']
print("#".join(numTuple))
except Exception as e:
print ("Error: ",e)
Output
enter number : 9
1#2#3#4
Thread - 1: Square: : 81
Thread - 2: Cube : : 729

· One min read
Kaustubh Kulkarni

Que > Program to creating a thread to print the even numbers from 10 to 20 by using Thread Class

file.py
from _thread import *
import threading as thread
def even(name,timer):
for i in range(10,20):
if i%2==0:
print(name+" : "+str(i))
try:
thread.start_new_thread( even, ("Thread", 2, ) )
except Exception as e:
print ("Error: ",e)
Output
Thread : 10
Thread : 12
Thread : 14
Thread : 16
Thread : 18

· One min read
Kaustubh Kulkarni

Que > Program to demonstrate the use if else block in Try Except block

file.py
def divider(x, y):
try:
result = x // y
except ZeroDivisionError:
print("Error: dividing by zero ")
else:
print("Answer is :", result)
finally:
print('Program Terminated')
divider(3, 2)
Output
Answer is : 1
Program Terminated