Saturday 8 June 2024

File Chooser using Python

 

from plyer import filechooser


# Open a file chooser dialog

file_path = filechooser.open_file()

print("Selected file:", file_path)


# Open multiple files chooser dialog

files_path = filechooser.open_file(multiple=True)

print("Selected files:", files_path)


# Save file chooser dialog

save_path = filechooser.save_file()

print("Save file path:", save_path)


#clcoding.com

Python Coding challenge - Day 224 | What is the output of the following Python Code?

 

Let's break down the code step by step:



cl = 4
while cl < 6:
    cl = cl + 1     print(cl, end='-')

Explanation

  1. Initialization:

    cl = 4

    Here, the variable cl is initialized to 4.

  2. While Loop Condition:

    while cl < 6:   
  3.  The while loop will continue to execute as long as the condition cl < 6 is True. Initially, cl is 4, so the condition is True.
  4. Inside the Loop:

    cl = cl + 1

    Inside the loop, cl is incremented by 1. The first time this statement is executed, cl becomes 5.
  5. Print Statement:

    print(cl, end='-')

    This prints the current value of cl followed by a hyphen -. The end='-' part ensures that the next output is printed immediately after the hyphen without moving to a new line.

Step-by-Step Execution

  • Initial State:

    cl is 4.
    The while condition cl < 6 is checked and is True.
  • First Iteration:

    cl = cl + 1 is executed, so cl becomes 5.
    print(cl, end='-') prints 5-.
  • Second Iteration:

      The while condition cl < 6 is checked again. Now cl is 5, so the condition is still True.cl = cl + 1 is executed again, so cl becomes 6.
      print(cl, end='-') prints 6-.
  • End of Loop:

    The while condition cl < 6 is checked once more. Now cl is 6, so the condition is False.
    The loop terminates.

Output

The output of this code will be:

5-6-

Each iteration of the loop increases the value of cl by 1 and prints it, followed by a hyphen. The loop stops running when cl reaches 6.

Friday 7 June 2024

Python Programming Basics: For Freshers Learn Python Programming Infrastructure and Attend Interviews free pdf

 

Python Programming Basics

For Freshers Learn Python Programming Infrastructure and Attend Interviews

What You Will Learn

Chapter 1 : Basics

1 Python Introduction

2 Python Variables


Chapter 2 : Data Types

1 Python boolean

2 Python String

3 Python Number

4 Python List

5 Python Tuple

6 Python Dictionary


Chapter 3 : Operators

1 Python Arithmetic Operators

2 Python Bitwise Operators

3 Python Comparison Operators

4 Python Logical Operators

5 Python Ternary Operators


Chapter 4 : Statements

1 Python if

2 Python while

3 Python for loop

4 Python pass

5 Python break

6 Python continue


Chapter 5 : Functions

1 Python function

2 Python Function Recursion


Chapter 6 : Object Oriented

1 Python Modules

2 Python class

3 Python class Inheritance

4 Python Abstract Base Classes

5 Python Operator Overloading


Chapter 7 : Advanced

1 Python File

2 Python Text File

3 Python Exceptions

4 Python Testing

Free PDF: Python Programming Basics: For Freshers Learn Python Programming Infrastructure and Attend Interviews


Hard Copy: Python Programming Basics: For Freshers Learn Python Programming Infrastructure and Attend Interviews





Monday 3 June 2024

Country Details using Python

 

from countryinfo import CountryInfo

country = CountryInfo(input("Enter Country Name:"))


# Various information about the country

print("Country Name:", country.name())

print("Capital:", country.capital())

print("Population:", country.population())

print("Area (in square kilometers):", country.area())

print("Region:", country.region())

print("Subregion:", country.subregion())

print("Demonym:", country.demonym())

print("Currency:", country.currencies())

print("Languages:", country.languages())

print("Borders: ", country.borders())

#clcoding.com

Sunday 2 June 2024

Print Calendar using Python

 

Let's break down the code and understand what it does step by step.

Code Explanation

Importing the Calendar Module:

from calendar import *

  • This line imports all the functions and classes from the calendar module in Python. The calendar module provides various functions related to calendar operations.

Getting User Input:

year = int(input('Enter Year:'))
  • This line prompts the user to enter a year. The input function takes the user's input as a string, and the int function converts this string to an integer, which is then stored in the variable year.

Printing the Calendar:

print(calendar(year, 2, 1, 8, 4))
  • This line is intended to print the calendar for the given year with specific formatting. 
formatyear(year, w=2, l=1, c=6, m=3):
  • year: The year for which the calendar is to be printed.
  • w: The width of each date column (default is 2).
  • l: The number of lines for each week (default is 1).
  • c: The number of spaces between month columns (default is 6).
  • m: The number of months per row (default is 3).

Python Coding challenge - Day 223 | What is the output of the following Python Code?

 

Let's break down the code and explain what it does:

my_num1 = -2 my_num2 = -3 print(my_num1 % my_num2)

Variable Assignment:

  • my_num1 = -2: This assigns the value -2 to the variable my_num1.
  • my_num2 = -3: This assigns the value -3 to the variable my_num2.

Modulus Operation:

  • The modulus operator % returns the remainder of the division of one number by another.
  • my_num1 % my_num2 computes the remainder when -2 is divided by -3.
  1. Calculation:

    • To understand the result of -2 % -3, we need to know how the modulus operation works with negative numbers.

    • The formula for the modulus operation is:

      𝑎%𝑏=𝑎(𝑏×int(𝑎/𝑏))

      where int(a / b) represents the integer division (floor division) of a by b.

    • Applying this to our numbers:

      2%3=2(3×int(2/3))
    • First, calculate the integer division:

      int(2/3)=int(0.666...)=0

      (since -2 / -3 is approximately 0.666, and taking the floor gives us 0).

    • Now, plug this back into the formula:

      2%3=2(3×0)=20=2
  2. Result:

    • Therefore, my_num1 % my_num2 results in -2.

Output:

  • print(my_num1 % my_num2) will print -2.

So, the final output of the code will be: -2

Popular Posts

Categories

AI (28) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (121) C (77) C# (12) C++ (82) Course (64) Coursera (182) Cybersecurity (24) data management (11) Data Science (99) Data Strucures (6) Deep Learning (11) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Pandas (3) PHP (20) Projects (29) Python (775) Python Coding Challenge (260) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses