Posts

Showing posts with the label Python

Python Programming| Class 11th Revision | Short Notes with example

Image
  #COMMAND Use of: if, elif, else, for, in, range #COMMAND Use of: while (loop) #COMMAND Use of: str (string) #COMMAND Use of: def (defining a function)

Python Code for Tic Tac Toe game | Between two Players | Computer Science

Here is the code for TIC TAC TOE game between two playersss.... import os import time board = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']     player = 1         ########win Flags##########     Win = 1     Draw = -1     Running = 0     Stop = 1     ###########################     Game = Running     Mark = 'X'         #This Function Draws Game Board     def DrawBoard():         print(" %c   %c   %c " % (board[1],board[2],board[3]))         print("__|__|__")              print(" %c   %c   %c " % (board[4],board[5],board[6]))         print("__|__|__")              print(" %c   %c   %c " % (board[7],board[8],board[9]))         print("__|__|__ ")         #This Function Checks position is empty or not     def CheckPosition(x):         if(board[x] == ' '):             return True         else:             return False         #This Function C

Python Codes | Codes to make calculater | Codes to make Tables | Code to find factorial of numbers | Computer Science | CS

 CODE 1: TO MAKE A CALCULATER IN PYTHON def add(x, y): return x+y def subtract(x, y): return x-y def multiply (x, y): return x*y def divide (x, y): return x/y print("select operation") print("1. Add") print("2. Subtract") print("3. Multiply") print("4. Divide") while True: choice=input("Enter choice (1/2/3/4):  ") if choice in ('1','2','3','4'): num1=float(input("enter first number:    ")) num2=float(input("enter second number:    ")) if choice  == '1': print(num1, "+", num2, "=", add(num1, num2)) elif choice == '2': print(num1, "-", num2,"=", subtract(num1, num2)) elif choice == '3': print(num1, "×", num2, "=", multiply(num1, num2)) elif choice == '4': print(num1, "÷", num2, "=", divide(num1, num2)) break else: