Saturday 3 July 2021

Python if / else

 Python if / else

a1=int(input("Enter the number:\n"))
a2=int(input("Enter the number:\n"))
a3=int(input("Enter the number:\n"))
a4=int(input("Enter the number:\n"))
if((a1>a2)and(a1>a3)and(a1>a4)):
    print(a1,"is greater than ",a2,a3,a4)
elif((a2>a1)and(a2>a3)and(a2>a4)):
    print(a2," is greater than",a1,a3,a4)
elif((a3>a1)and(a3>a2)and(a3>a4)):
    print(a3," is greater than",a2,a1,a4)
else:
    print(a4," is greater than",a2,a3,a1)
    

a1=int(input("Enter the number:\n"))
a2=int(input("Enter the number:\n"))
a3=int(input("Enter the number:\n"))
a4=int(input("Enter the number:\n"))
if(a1>a4):
    f1=a1
else:
    f1=a4
if(a2>a3):
    f2=a2
else:
    f2=a3
if(f1>f2):
    print(f1,"is a greater")
else:
    print(f2,"is a greater")


comment=input("Enter the comment :\n")
Spam=False
if("make a lot of moneyin comment):
    Spam=True
elif("buy nowin comment):
    Spam=True
elif("subcribe thisin comment):
    Spam=True
elif("click thisin comment):
    Spam=True
else:
    Spam=False
if(Spam):
    print("text is a spam")
else:
    print("text is not a spam")



Username=input("Enter the user name :\n")
a=int(len(Username))
# print(a)
if(a<10):
    print("Yes")
else:
    print("NO")



l1=["ram","shaam","upendra","nitesh","maya"]

name=input("Enter the name U want:\n")
if(name in l1):
    print("yes")
else:
    print("No")

marks=int(input("Enter the marks obtained :\n"))
if(marks>=90 and marks<=100):
    pgrade='Ex'
elif(marks>=80 and marks<=90):
    grade='A'
elif(marks>=70 and marks<=80):
    grade='B'
elif(marks>=60 and marks<=70):
    grade='C'
elif(marks>=50 and marks<=60):
    grade="D"
else:
    grade="F"

print("Your grade is "+grade)



post=input("Enter the post:\n")
if("harryin post):
    print("yes")
elif("Harryin post):
    print("yes")
elif("HaRRyin post):
    print("yes")
elif("HArryin post):
    print("yes")
elif("HArrYin post):
    print("yes")
elif("HARRYin post):
    print("yes")
else:
    print("no")


age=int(input("Enter the age:\n"))
if(age>=18):
    print("yes")
else:
    print("no")



a=20
if(a>10):
    print(,"is greater than 10")
elif(a>5):
    print("a is greater than 20")
else:
    print("a is not greater than 20 nor equal to 20")




Python Sets and Dictonaries

 Python Sets and Dictonaries 

HindiDic={
    "kaam":"work",
    "aam":"mango",
    "kitab":"book",
    "naam":"name"
}
print("Option are",HindiDic.keys())
print("the value of the dictionary is ",HindiDic.values())
a=input("Enter the hindi words:\n")
print("English meaning is :",HindiDic.get(a))


n1=int(input("Enter the  number1:\n"))
n2=int(input("Enter the  number2:\n"))
n3=int(input("Enter the  number3:\n"))
n4=int(input("Enter the  number4:\n"))
n5=int(input("Enter the  number5:\n"))
n6=int(input("Enter the  number6:\n"))
n7=int(input("Enter the  number7:\n"))
n8=int(input("Enter the  number8:\n"))

number_set={n1,n2,n3,n4,n5,n6,n7}
print(number_set)
number_set.add(200)
number_set.add((25,50,150,456))
print(number_set)


a=int(input("Enter the value :\n"))
b=input("Enter the values:\n")
ab_set={a,b}
print(ab_set)
s={18,'18'}
print(s)


s=set()
s.add(20)
s.add("20")
s.add(20.0)

print(len(s))
print(s)


myfriend={}
languague1 = input("Enter yours fav computer languague:\n")
languague2 = input("Enter yours fav computer languague:\n")
languague3 = input("Enter yours fav computer languague:\n")
languague4 = input("Enter yours fav computer languague:\n")
myfriend["upendra"]=languague1
myfriend["ram"]=languague2
myfriend["shaam"]=languague3
myfriend["upendra"]=languague1
print(myfriend)
myfriend["upendra"]="c++"
myfriend.update({"nitesh":"cout"})
print(myfriend)


Python List and Tuple

 f1=input("Enter the name of fruits 1: \n")

f2=input("Enter the name of fruits 2: \n")
f3=input("Enter the name of fruits 3: \n")
f4=input("Enter the name of fruits 4: \n")
f5=input("Enter the name of fruits 5: \n")
f6=input("Enter the name of fruits 6: \n")
f7=input("Enter the name of fruits 7: \n")
fruit_list=[f1,f2,f3,f4,f5,f6,f7]
print(fruit_list)



marks_student1=input("Enter the marks of student 1:\n")
marks_student2=input("Enter the marks of student 2:\n")
marks_student3=input("Enter the marks of student 3:\n")
marks_student4=input("Enter the marks of student 4:\n")
marks_student5=input("Enter the marks of student 5:\n")
marks_student6=input("Enter the marks of student 6:\n")
marks_lists=[marks_student1,marks_student2,marks_student3,marks_student4,marks_student5,marks_student6]
print(marks_lists)
marks_lists.sort()
print(marks_lists)
print(marks_lists[0])

t=(1,2,3,4,8,10,35,1,1,"upendra")
print(t)
# t[3]=12
print(t.index(10))


l1=["upendra",12,1,45,14.02,True,"harry"]
print(l1)
l1.append(4)
print(l1)


a=[1,45,85,785]
print(a[0]+a[1]+a[2]+a[3])
a[3]=456230
print(a[0]+a[1]+a[2]+a[3])
print(sum(a))


t1=(1,"hello",12,1,0,0,456.2,0,"harry")
print(t1.count(0))

Friday 25 June 2021

Snake gun and water game in c programming

 Snake gun and water game in c programming 

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int snakewatergun(char youchar comp)
{
    // return 0 for draw return -1 for lose and return 1 for wining
    if (you == comp)
    {
        return 0;
    }
    else if (you == 's' && comp == 'w')
    {
        return 1;
    }
    else if (you == 'w' && comp == 's')
    {
        return -1;
    }
    else if (you == 'g' && comp == 's')
    {
        return 1;
    }
    if (you == 's' && comp == 'g')
    {
        return -1;
    }
    if (you == 'w' && comp == 'g')
    {
        return 1;
    }
    else if (you == 'g' && comp == 'w')
    {
        return -1;
    }
}

int main()
{

    char youcomp;
    int number;
    srand(time(0));
    number = rand() % 100 + 1;
    if (number < 33)
    {
        comp = 's';
    }
    else if (number > 33 && number < 66)
    {
        comp = 'w';
    }
    else
    {
        comp = 'g';
    }

    printf("Enter the snake 's' , water 'w' and gun 'g':\n");
    scanf("%c"&you);
    int result = snakewatergun(youcomp);
    // result 0 draw and if result 1 you win and if
    // result -1 you lose
    printf("you choosen '%c' and computer choosen '%c'\n"youcomp);
    if (result == 0)
    {
        printf("Game Draw\n");
    }
    else if (result == 1)
    {
        printf("You win\n");
    }
    else if (result == -1)
    {
        printf("You loose\n");
    }

    return 0;
}

Dynamic memory Allocation in c program

 Dynamic memory Allocation in c program 

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int *ptr;
   int num;
   printf("Enter the no of interger U want :\n");
   scanf("%d"&num);
   ptr = (int *)calloc(numsizeof(int));
   for (int i = 0i < numi++)
   {
      printf("Enter the value of element %d is :\n"i + 1);
      scanf("%d"&ptr[i]);
   }
   for (int i = 0i < numi++)
   {
      printf("the value of element %d is: %d \n"i + 1ptr[i]);
   }
   free(ptr);

   return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
  float *ptr;
  ptr = (float *)malloc(8 * sizeof(float));
  ptr = realloc(ptr14 * sizeof(float));
  free(ptr);
  for (int i = 0i < 8i++)
  {
    printf("Enter the value of element %d is :\n"i + 1);
    scanf("%f"&ptr[i]);
  }
  for (int i = 0i < 5i++)
  {
    printf("the value of element %d is %f \n"i + 1ptr[i]);
  }

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
  float *ptr;
  ptr = (float *)malloc(8 * sizeof(float));
  for (int i = 0i < 8i++)
  {
    printf("Enter the value of element %d is :\n"i + 1);
    scanf("%f"&ptr[i]);
  }
  for (int i = 0i < 5i++)
  {
    printf("the value of element %d is %f \n"i + 1ptr[i]);
  }

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{

   int *ptr;
   ptr = (int *)malloc(10 * sizeof(int));
   printf("Multiplication Table of Seven is :\n");
   for (int i = 0i < 10i++)
   {
      printf(" %d*%d=%d\n"7i + 17 * (i + 1));
   }
   printf("printing table using realloc memory\n");
   ptr = realloc(ptr15 * sizeof(int));
   for (int i = 0i < 15i++)
   {
      printf(" %d*%d=%d\n"7i + 17 * (i + 1));
   }

   return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
   int *ptr;
   ptr = (int *)malloc(5 * sizeof(int));
   for (int i = 0i < 5i++)
   {
      printf("Enter the value of element %d is :\n"i + 1);
      scanf("%d"&ptr[i]);
   }
   for (int i = 0i < 5i++)
   {
      printf(" the value of element %d is :%d\n"i + 1ptr[i]);
   }
   ptr = realloc(ptr10 * sizeof(int));
   for (int i = 0i < 10i++)
   {
      printf("Enter the value of element %d is :\n"i + 1);
      scanf("%d"&ptr[i]);
   }
   for (int i = 0i < 10i++)
   {
      printf(" the value of element %d is :%d\n"i + 1ptr[i]);
   }

   return 0;
}






file input and output in c program

 file input and output in c program

#include <stdio.h>
typedef struct employees
{
    int salary;
    char name[20];
emp;

int main()
{
    FILE *ptr;
    ptr = fopen("a.text""w");
    emp e1e2;
    printf("enter the name of e1:");
    scanf("%s"e1.name);
    printf("enter the salary of e1:");
    scanf("%d"&e1.salary);
    printf("enter the name of e2:");
    scanf("%s"e2.name);
    printf("enter the salary of e2:");
    scanf("%d"&e2.salary);

    fprintf(ptr"%s\t,"e1.name);
    fprintf(ptr"%d\n"e1.salary);
    fprintf(ptr"%s\t,"e2.name);
    fprintf(ptr"%d"e2.salary);
    fclose(ptr);

    return 0;
}


#include <stdio.h>

int main()
{
    FILE *ptr;
    char c;
    ptr = fopen("getdemo.text""r");
    c = fgetc(ptr);
    while (c != EOF)
    {
        printf("%c"c);
        c = fgetc(ptr);
    }

    fclose(ptr);
    return 0;
}


#include <stdio.h>

int main()
{
     FILE *ptr1;
     FILE *ptr2;
     ptr1 = fopen("single.text""r");
     ptr2 = fopen("double.text""w");
     int numnum2;
     fscanf(ptr1"%d"&num);
     num2 = 2 * num;
     fprintf(ptr2"%d"num2);

     return 0;
}


# include<stdio.h> 

 int main(){ 
FILE *ptr;
ptr=fopen("upen1.text","w");
int num=25;
fprintf(ptr,"the number is %d \n",num);
fprintf(ptr,"thanks for using it ");
fclose(ptr);
     
     return 0
}


#include <stdio.h>

int main()
{
  int numnum1;
  FILE *ptr;
  ptr = fopen("upen.text""r");
  if (ptr == NULL)
  {
    printf("this file doesn't exist");
  }
  else
  {
    fscanf(ptr"%d%d"&num&num1);
    printf("The number is %d \n"num);
    printf("The number is %d \n"num1);
    fclose(ptr);
  }

  return 0;
}


#include <stdio.h>

int main()
{
     FILE *ptr;
     char c;
     ptr = fopen("fputdemo.text""w");
     c = fputc('M'ptr);
     c = fputc('O'ptr);
     c = fputc('B'ptr);
     c = fputc('I'ptr);
     c = fputc('L'ptr);
     c = fputc('E'ptr);
     fclose(ptr);

     return 0;
}


#include <stdio.h>

int main()
{
   int mul[10];
   int num;
   FILE *ptr;
   ptr = fopen("Mul.text""w");
   printf("Enter the number of which table U want:");
   scanf("%d"&num);
   for (int i = 0i < 10i++)
   {
      mul[i= num * (i + 1);
   }
   for (int i = 0i < 10i++)
   {
      fprintf(ptr"%d*%d=%d\n"num, (i + 1), mul[i]);
   }

   return 0;
}


#include <stdio.h>

int main()
{
     FILE *ptr;
     ptr = fopen("a.text""r");
     int num[2];
     fscanf(ptr"%d%d%d"&num[0], &num[1], &num[2]);
     printf("%d \n"num[0]);
     printf("%d \n"num[1]);
     printf("%d \n"num[2]);

     return 0;
}


#include <stdio.h>

int main()
{
    FILE *ptr;
    ptr = fopen("Table.text""w");
    int num;
    printf("Enter the number:");
    scanf("%d"&num);
    for (int i = 0i < 10i++)
    {
        fprintf(ptr"%d*%d=%d\n"num, (i + 1), num * (i + 1));
    }
    fclose(ptr);

    fprintf("sucessfuly generated table of %d"num);

    return 0;
}


#include <stdio.h>

int main()
{
   FILE *ptr1;
   FILE *ptr2;
   ptr1 = fopen("file.text""r");
   ptr2 = fopen("file1.text""w");
   char c;
   c = fgetc(ptr1);
   while (c != EOF)
   {
      fputc(cptr2);
      fputc(cptr2);
      c = fgetc(ptr1);
   }
   fclose(ptr1);
   fclose(ptr2);

   return 0;
}



Pointer in c program problems

 Pointer in c program problems

#include <stdio.h>

int main()
{
    int i = 34;
    int *j = &i;
    int **k = &j;
    int ***l = &k;
    // int *ch_integer=&i;
    printf("the value of i is %d \n "i);
    printf("the value of i is %d \n "*(&i));
    printf("the address of i is %u \n "&i);
    printf("the add of j is %u \n "&j);
    printf("the value of j is %d \n "j);
    printf("the value of j is %d \n "*(&j));
    printf("the value of k is %d \n"*(&k));
    printf("the add of l is %d \n", (&l));
    printf("the value of l is %d \n"*(&l));
    // printf("the value of i is %d ", i);

    return 0;
}


#include <stdio.h>

int main()
{
    int x = 9;
    int *y = &x;
    printf("the add of x is %u \n"&x);
    printf("the value of x is %d \n"*(&x));
    printf("the value of x is %d \n"*y);
    printf("the add of y is %u \n"&y);
    printf("the value of y is %d \n"y);

    return 0;
}


#include <stdio.h>
void add(int a);
int main()
{
    int i = 4;
    printf("the value of i is %d \n"i);
    add(4);
    printf("the add of i is %u \n"&i);

    return 0;
}

void add(int a)
{
    printf("the add of a is %u\n"&a);
}


#include <stdio.h>
void change_10(int *a);
int main()
{
    int x;
    x = 10;
    printf("the value of x before is %d\n"x);
    change_10(&x);
    printf("the value of x after is %d "x);

    return 0;
}
void change_10(int *a)
{
    int temp;
    temp = *a * 10;
    *a = temp;
}


#include <stdio.h>
int sum(int *aint *b);
int avg(int *aint *b);
int main()
{
    int xyresultsresults1;
    printf("Enter the value of X and Y:\n");
    scanf("%d%d"&x&y);
    results = sum(&x&y);
    printf("the value of sum is %d\n"results);
    results1 = avg(&x&y);
    printf("the value of avg is %d\n"results1);

    return 0;
}
int sum(int *aint *b)
{
    return *a + *b;
}
int avg(int *aint *b)
{
    return (*a + *b/ 2;
}



#include <stdio.h>
void SumandAvg(int aint bint *sumfloat *avg)
{
    *sum = a + b;
    *avg = (float)(*sum / 2);
}
int main()
{
    int xysum;
    float avg;
    x = 267;
    y = 120;
    SumandAvg(xy&sum&avg);
    printf("The value of sum is %d \n"sum);
    printf("The value of avg is %f \n"avg);

    return 0;
}


#include <stdio.h>

int main()
{
    int i = 5;
    int *j = &i;
    int **k = &j;
    printf("the value of i is %d "*(*k));

    return 0;
}


#include <stdio.h>
void change(int a)
{
    int temp;
    temp = a * 10;
    a = temp;
}
int main()
{
    int x = 10;
    printf("The value of x before %d\n"x);
    change(x);
    printf("The value of x after %d"x);

    return 0;
}


#include <stdio.h>

void swap(int *aint *b);

int main()
{
    int x = 32y = 45;
    printf("the value of swap before %d , %d \n "xy);
    swap(&x&y);
    printf("the value of swap after %d , %d \n "xy);

    return 0;
}
void swap(int *aint *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

Python if / else

 Python if / else a1 = int ( input (" Enter the number: \n ")) a2 = int ( input (" Enter the number: \n ")) a3 = int ( i...