Skip to content
🤔prompts chat🧠
🔍
question:Use Python to convert a single number from binary to decimal 10011

answer:def binary2decimal(binary): dec = 0 for i in range(len(binary)): digit = binary[i] dec += int(digit)*(2**(len(binary)-1-i)) return dec print(binary2decimal("10011")) # 19

question:Create an algorithm in Python to count all the even numbers in a given list of numbers [1, 2, 3, 4, 5, 6]

answer:def count_even(array): count = 0 for num in array: if num % 2 == 0: count += 1 return count arr = [1, 2, 3, 4, 5, 6] print(count_even(arr)) # Output: 3

question:Generate a program to take a sentence and capitalize the first letter of each word in the sentence.

answer:def capitalize_sentence(sentence): words = sentence.split(' ') capitalized_words = [word.capitalize() for word in words] return ' '.join(capitalized_words) # Driver Code sentence = 'i am learning python' result = capitalize_sentence(sentence) print(result) # prints "I Am Learning Python"

question:Create a Python function to remove all the elements in a list that are greater than a specified value. [1, 2, 3, 4, 5], 3

answer:def remove_greater_than(arr, value): new_arr = [] for item in arr: if item <= value: new_arr.append(item) return new_arr result = remove_greater_than([1, 2, 3, 4, 5], 3) print(result)

Released under the MIT License.

has loaded