# Number triangle pattern
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=" ")
print()
# @python_Codes_pro
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=" ")
print()
# @python_Codes_pro
👍1
# Star Pyramid pattern
rows = 5
for i in range(0, rows):
for j in range(0, rows - i - 1):
print(end=" ")
for j in range(0, i + 1):
print("*", end=" ")
print()
# @python_Codes_pro
rows = 5
for i in range(0, rows):
for j in range(0, rows - i - 1):
print(end=" ")
for j in range(0, i + 1):
print("*", end=" ")
print()
# @python_Codes_pro
👍1
# Dimond pattern
rows = 5
for i in range(1, rows + 1):
for j in range(1, rows - i + 1):
print(end=" ")
for j in range(1, 2 * i):
print("*", end="")
print()
for i in range(rows - 1, 0, -1):
for j in range(1, rows - i + 1):
print(end=" ")
for j in range(1, 2 * i):
print("*", end="")
print()
# @python_Codes_pro
rows = 5
for i in range(1, rows + 1):
for j in range(1, rows - i + 1):
print(end=" ")
for j in range(1, 2 * i):
print("*", end="")
print()
for i in range(rows - 1, 0, -1):
for j in range(1, rows - i + 1):
print(end=" ")
for j in range(1, 2 * i):
print("*", end="")
print()
# @python_Codes_pro
All Codes
@C_Code5
@CPP_Coding
@Python_Codes_Pro
@Java_Codes_Pro
@jsCode0
Diffrent free Compiler bots
For group @CodeCompiler_Bot
For channel @IOChannel_bot
For Channel Cmpl @Compiler0bot
For inline @cmpbbot
info in @LogicBots
Discussion
@bca_mca_btech
@C_Code5
@CPP_Coding
@Python_Codes_Pro
@Java_Codes_Pro
@jsCode0
Diffrent free Compiler bots
For group @CodeCompiler_Bot
For channel @IOChannel_bot
For Channel Cmpl @Compiler0bot
For inline @cmpbbot
info in @LogicBots
Discussion
@bca_mca_btech
# get lyrics of any song
import urllib.request
url = 'https://song.panditsiddharth.repl.co/lyrics?song=har+har+shambhu'
response = urllib.request.urlopen(url)
data = response.read().decode('utf-8')
print(data)
# @python_codes_pro
import urllib.request
url = 'https://song.panditsiddharth.repl.co/lyrics?song=har+har+shambhu'
response = urllib.request.urlopen(url)
data = response.read().decode('utf-8')
print(data)
# @python_codes_pro
# function declaration in Python
def sum():
return 6 + 7
print(sum())
def sum():
return 6 + 7
print(sum())
# Some more examples of functions
# under """ these three inverted commas are string which is used as comment in Python
def greet(name):
"""
This function takes a name as input and prints a greeting message.
"""
print(f"Hello, {name}!")
def multiply(x, y):
"""
This function takes two numbers as input and returns their product.
"""
return x * y
def is_even(number):
"""
This function checks if a given number is even and returns a boolean value.
"""
return number % 2 == 0
# Calling the functions
greet("Alice")
product = multiply(4, 5)
print(product)
print(is_even(7))
print(is_even(10))
# under """ these three inverted commas are string which is used as comment in Python
def greet(name):
"""
This function takes a name as input and prints a greeting message.
"""
print(f"Hello, {name}!")
def multiply(x, y):
"""
This function takes two numbers as input and returns their product.
"""
return x * y
def is_even(number):
"""
This function checks if a given number is even and returns a boolean value.
"""
return number % 2 == 0
# Calling the functions
greet("Alice")
product = multiply(4, 5)
print(product)
print(is_even(7))
print(is_even(10))
🔥1
# its Curried function
def multiply(a):
def inner(b):
return a * b
return inner
# Curried function can be used with partial application
multiply_by_two = multiply(2)
print(multiply_by_two(4)) # Output: 8
# Or it can be invoked with all arguments at once
print(multiply(3)(5))
# @Python_Codes_pro
def multiply(a):
def inner(b):
return a * b
return inner
# Curried function can be used with partial application
multiply_by_two = multiply(2)
print(multiply_by_two(4)) # Output: 8
# Or it can be invoked with all arguments at once
print(multiply(3)(5))
# @Python_Codes_pro
# taking inputs in Python
name = input("Enter your name: ")
print("Your name is", name)
# @Python_Codes_pro
name = input("Enter your name: ")
print("Your name is", name)
# @Python_Codes_pro
👍2
# taking numbers in Python
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
# typecasting string to number
num1 = int(num1)
num2 = int(num2)
print("Sum of numbers is", num1 + num2)
# @Python_Codes_pro
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
# typecasting string to number
num1 = int(num1)
num2 = int(num2)
print("Sum of numbers is", num1 + num2)
# @Python_Codes_pro
👍2❤1
Running codes by buttons feature
Powered by
@IOChannel_bot
See more about this bot in
@LogicBots channel
Powered by
@IOChannel_bot
See more about this bot in
@LogicBots channel
👏1
# use of requests module to fetch anything
import requests
url = "https://api.chucknorris.io/jokes/random"
response = requests.get(url)
data = response.json()
joke = data["value"]
print(joke)
import requests
url = "https://api.chucknorris.io/jokes/random"
response = requests.get(url)
data = response.json()
joke = data["value"]
print(joke)
# fetching lyrics
import requests
url = 'https://song.panditsiddharth.repl.co/lyrics?song=har+har+shambhu'
lyrics = requests.get(url).text
print(lyrics)
import requests
url = 'https://song.panditsiddharth.repl.co/lyrics?song=har+har+shambhu'
lyrics = requests.get(url).text
print(lyrics)
String functions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
@python_codes_pro
1.
len(str): Returns the length of the string.2.
str.lower(): Returns a copy of the string in lowercase.3.
str.upper(): Returns a copy of the string in uppercase.4.
str.capitalize(): Returns a copy of the string with the first character capitalized.5.
str.title(): Returns a copy of the string with the first character of each word capitalized.6.
str.strip(): Returns a copy of the string with leading and trailing whitespace removed.7.
str.startswith(prefix): Returns True if the string starts with the specified prefix; otherwise, returns False.8.
str.endswith(suffix): Returns True if the string ends with the specified suffix; otherwise, returns False.9.
str.format(*args, **kwargs): Formats the string by replacing placeholders with provided values.10.
str.replace(old, new): Returns a copy of the string with all occurrences of old replaced by new.11.
str.split(sep=" "): Splits the string into a list of substrings based on the specified separator sep (default is space).12.
str.join(iterable): Concatenates elements of the iterable sequence into a single string using str as the separator.13.
str.isdigit(): Returns True if all characters in the string are digits; otherwise, returns False.14.
str.isalpha(): Returns True if all characters in the string are alphabetic; otherwise, returns False.15.
str.isnumeric(): Returns True if all characters in the string are numeric; otherwise, returns False.@python_codes_pro
👍5❤4
# fetch song lyrics
url = "https://song.panditsiddharth.repl.co/lyrics?song=ae+watan"
import requests as r
print(r.get(url).text)
# @Python_Codes_Pro
url = "https://song.panditsiddharth.repl.co/lyrics?song=ae+watan"
import requests as r
print(r.get(url).text)
# @Python_Codes_Pro
# fetch song link with title
song = "ae watan"
url = "https://song.panditsiddharth.repl.co/song?song=" + song
import requests as r
print(r.get(url).text)
# @Python_Codes_Pro
song = "ae watan"
url = "https://song.panditsiddharth.repl.co/song?song=" + song
import requests as r
print(r.get(url).text)
# @Python_Codes_Pro
# Run and see its output
message = chr(32) + chr(72) + chr(97) + chr(112) + chr(112) + chr(121) + chr(32) + chr(73) + chr(110) + chr(100) + chr(101) + chr(112) + chr(101) + chr(110) + chr(100) + chr(101) + chr(110) + chr(99) + chr(101) + chr(32) + chr(100) + chr(97) + chr(121) + chr(33)
print('\U0001F1EE\U0001F1F3' + message)
# @python_codes_pro
message = chr(32) + chr(72) + chr(97) + chr(112) + chr(112) + chr(121) + chr(32) + chr(73) + chr(110) + chr(100) + chr(101) + chr(112) + chr(101) + chr(110) + chr(100) + chr(101) + chr(110) + chr(99) + chr(101) + chr(32) + chr(100) + chr(97) + chr(121) + chr(33)
print('\U0001F1EE\U0001F1F3' + message)
# @python_codes_pro
😁4👍1
❤3