i=int(input(“enter total numbers”)) c=[] for j in range(i): c.append(int(input(“Enter a number”))) print(c) d=max(c) print(d)
python CopyEdit num = int(input(“Enter a number: “)) if num % 2 == 0: print(“Even”) else: print(“Odd”)
Format Specifiers in Python Python provides format specifiers for formatting strings, numbers, and other data types. These specifiers can be used with f-strings (f””), the format() method, or % formatting. 1. Integer Formatting Format Description Example %d or {} Integer (decimal) print(f”{100:d}”) → 100 %o or {:#o} Octal representation print(f”{100:o}”) → 144 %x or {:#x}…
# Integer int_var = 42 print(“Integer:”, int_var, type(int_var)) # Float float_var = 3.14 print(“Float:”, float_var, type(float_var)) # Complex complex_var = 2 + 3j print(“Complex:”, complex_var, type(complex_var)) # Boolean bool_var = True print(“Boolean:”, bool_var, type(bool_var)) # String str_var = “Hello, Python!” print(“String:”, str_var, type(str_var)) # List (ordered, mutable collection) list_var = [1, 2, 3, “Python”, 4.5]…
Python has several built-in data types that help in storing and manipulating different kinds of data. Below is a detailed discussion of the various data types in Python: 1. Numeric Types Numeric data types store numbers and support arithmetic operations. a. int (Integer) Represents whole numbers (positive, negative, or zero). No limit on size (depends…
The .upper() method in Python is used to convert a string to uppercase. Syntax: string.upper() Example Usage: text = “hello world” upper_text = text.upper() print(upper_text) # Output: HELLO WORLD Calling upper() on a variable: name = “Python” print(name.upper()) # Output: PYTHON Calling upper() directly on a string literal: print(“hello”.upper()) # Output: HELLO Would you like…
C, C++, and Java are three prominent programming languages, each with its own unique features and use cases. Here’s a detailed comparison of these languages across various aspects: ### 1. **Origin and Paradigm** – **C:** – **Origin**: Developed in the early 1970s by Dennis Ritchie at Bell Labs. – **Paradigm**: Procedural programming language. It focuses…
In Java, labeled loops are a way to give a name (label) to a loop, allowing you to control the flow of execution in nested loops. This is especially useful when you want to break out of or continue a specific outer loop from within an inner loop. Labels are essentially identifiers that you place…
In Java, literals are specific values that are directly used in the code, and they represent constant values. Java literals can be categorized into several types based on the kind of data they represent. Here’s a breakdown of the different types of literals in Java: 1. Integer Literals These are whole numbers without any fractional…
In Java, type casting refers to the process of converting a variable from one type to another. This is necessary when you need to assign a value of one data type to a variable of another data type. Java supports two main types of casting: implicit (automatic) and explicit (manual). 1. Implicit Casting (Automatic Casting)…