Underrated step for logic building in programming.

Image
Logic building is a crucial and complex skill in programming. In essence, it is ability to come-up with solution of coding problem and write precise instructions ( or code) that a computer can execute autonomously. This skill requires aligning your thought process with computer and its capabilities. And running through code some-what abstractly to know and predict the behavior of code before it is executed. To be able to do this, one essential step that many beginner programmers overlook is performing dry runs. Understanding Dry Runs The concept of a dry run in programming is straightforward: can you mentally execute your code and predict its output without actually running it on a computer? While this seems simple, it is a challenging task. Typically, we are taught to write code, run it, and observe the output. This cycle is essential because code needs to run to be validated. However, if you rely solely on running your code to understand its behavior, you may struggle with building

Python Code for beginner's #7

1. Write code for to print multiplication table with given input. 

# function with argument


def multiplication_table(num, up_to):
result_list = []
for i in range(up_to + 1):
result = num * i
result_list.append(f"{num} x {i} = {result}")
return result_list


# Example usage:
num = 5
up_to = 10
table_results = multiplication_table(num, up_to)

# Print the results
for result in table_results:
print(result)

# function with argument

def multiplication_table():
num = int(input('enter num: '))
up_to = int(input('upto which value you want: '))
result_list = []
for i in range(up_to + 1):
result = num * i
result_list.append(f"{num} x {i} = {result}")
return result_list


table_results = multiplication_table()

# Print the results
for result in table_results:
print(result)

# procedure with argument

def multiplication_table(num, up_to):

for i in range(up_to + 1):
result = num * i
print(f"{num} x {i} = {result}")

# Example usage:
multiplication_table(2,4)


# procedure without argument

def multiplication_table():
num = int(input('enter num: '))
up_to = int(input('upto which value you want: '))
for i in range(up_to + 1):
result = num * i
print(f"{num} x {i} = {result}")

multiplication_table()

# function with argument

def isPalidrome(n):
temp = n
reverse_num=0

while n >0:
digit= n% 10
reverse_num = reverse_num * 10 + digit
n = n // 10

if temp == reverse_num:
return True
else:
return False

result = isPalidrome(55)
if result:
print('is palindrome')
else:
print('not palindrome')


# function without argument

def isPalidrome():
n = int(input('enter num: '))
temp = n
reverse_num=0

while n >0:
digit= n% 10
reverse_num = reverse_num * 10 + digit
n = n // 10

if temp == reverse_num:
return True
else:
return False

result = isPalidrome()
if result:
print('is palindrome')
else:
print('not palindrome')


# procedure without argument

def isPalindrome():
n = int(input('enter num: '))
temp = n
reverse_num=0

while n >0:
digit= n% 10
reverse_num = reverse_num * 10 + digit
n = n // 10

if temp == reverse_num:
print(f"{temp} is a palindrome.")
else:
print(f"{temp} is not a palindrome.")

isPalindrome()


# procedure with argument

def isPalindrome(n):
temp = n
reverse_num = 0

while n > 0:
digit = n % 10
reverse_num = reverse_num * 10 + digit
n = n // 10

if temp == reverse_num:
print(f"{temp} is a palindrome.")
else:
print(f"{temp} is not a palindrome.")


isPalindrome(444)

Comments

Popular posts from this blog

Building JavaScript Array Methods from Scratch in 2024 - Easy tutorial for beginners # 1

Build eisenhower matrix with React, firebase and neumorphism ui . (Part one)

Creating a Dynamic Search Bar in React: A Step-by-Step Tutorial