Skip to content

Instantly share code, notes, and snippets.

@ri-sh
Last active September 15, 2015 18:39
Show Gist options
  • Save ri-sh/890e92912f2c4f2ec1bf to your computer and use it in GitHub Desktop.
Save ri-sh/890e92912f2c4f2ec1bf to your computer and use it in GitHub Desktop.
def my (a , b ):
#function declaration a , b parameters hai
#question mein my(12,'abc123') likha hai toh a mein 12 jayega aur b= 'abc123'
ans =0
for i in b:
#agar i digit hai . if( ord(i)>=ord('0') and ord(i)<=ord('9')) iske jagah yeh bhi likh skta hai //
if(i.isdigit()):
ans= ans*10+ int(i) # int(i) i ko intigeger mein covrt krega
# i= '1' , int(i) se woh 1 hojayegaa
ans= ans+a # ans = 123 a = 12 123 +12 = 135
return ans
print my(12,'abc123') # yeh function call hai ismein parameters dala hai tu 12,'abc123' toh 12 a mein jayega aur abc123 b mei
numerator = 2.0
denominator= 9.0
ans = 0.0 # 0.0 becoz ans toh decimal float mein hi hoga warna example 0 + 3/2 =1 hoga kyun 3/2 integer division hoga
n= input('enter how many terms in the series ')
for i in range(n):
ans=ans+(numerator/denominator)*(-1**i) #i 0 se n-1
print str( numerator)+'/'+str(denominator) ,# yeh wala print statement ke bina run krke dekhna
numerator = numerator + 3
denominator=denominator+4
print ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment