Python Refute Code[RA2411003011193]
Python Refute Code[RA2411003011193]
Submitted by
Code:
second_largest = largest
largest = num
second_largest = num
Output:
Error: The error occurs when there are duplicate largest numbers in the list. In such a case,
the second_largest remains as -inf
Solution:
Code:
nums = list(map(int, input("Enter numbers separated by spaces: ").split()))
if len(nums) < 2:
else:
# Loop through the numbers to find the largest and second largest
second_largest = largest
largest = num
second_largest = num
if second_largest == float('-inf'):
else:
Output:
Refuge:
The error occurs when there are duplicate largest numbers in the list. In such a case, the
second_largest remains as -inf, which triggers the "same number is entered" message.
Problem Statement 2:
An code with indentation error.
Code:
def greet_user(name):
print(f"Hello, {name}!")
print("Welcome to the Python world!") # Indentation error here
def main():
user_name = input("Enter your name: ")
greet_user(user_name)
if __name__ == "__main__":
main()
Output:
Error: The second print("Welcome to the Python world!") is not properly indented. It should
be inside the greet_user function but is indented incorrectly, leading to an IndentationError.
In Python, the body of a function or control structure must be indented consistently.
Code:
def greet_user(name):
print(f"Hello, {name}!")
print("Welcome to the Python world!") # Correct indentation
def main():
user_name = input("Enter your name: ")
greet_user(user_name)
if __name__ == "__main__":
main()
Output: