28 Feb 2015

Java program to find factorial

//JAVAimport java.util.Scanner;class Factorial{   public static void main(String args[])   {      int n, c, fact = 1;      System.out.println("Enter an integer to calculate it's factorial");      Scanner in = new Scanner(System.in);     ...

Categories: , , ,

8 Feb 2015

Quiz

#Python #Quiz   #Problem 4 def myLog(x, b):    '''    x: a positive integer    b: a positive integer; b >= 2    returns: log_b(x), or, the logarithm of x relative to a base b.    '''    if x < b:        return...

Categories: , , , , , , , , , , ,

The 6.00 Word Game

# Python # The 6.00 Word Game # Problem Set 4A   from ps4a import *import time# Problem #6: Computer chooses a worddef compChooseWord(hand, wordList, n):    """    Given a hand and a wordList, find the word that gives     the maximum value score, and return it.    This word should be...

Categories: , , , , ,

The 6.00 Word Game

#Python   # 6.00x Problem Set 4A# The 6.00 Word Gameimport randomimport stringVOWELS = 'aeiou'CONSONANTS = 'bcdfghjklmnpqrstvwxyz'HAND_SIZE = 7SCRABBLE_LETTER_VALUES = {    'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't':...

Categories: , , , ,

Hangman game

# Python # Problem Set 3 # Hangman game import randomimport stringWORDLIST_FILENAME = "words.txt"def loadWords():    """    Returns a list of valid words. Words are strings of lowercase letters.        Depending on the size of the word list, this function may    take...

Categories: , , ,

Minimum Monthly Payment of Credit Card using Bisection Search

#Python ''' Program to calculate minimum Monthly Payment of a Credit Card using Bisection Search ''' balance = 320000annualInterestRate = 0.2newbalance=balancei=1monthlyInterestRate=annualInterestRate/12.0lowerb=newbalance/12.0upperb=(newbalance *(1+monthlyInterestRate)**12)/12.0minimumMonthlyPay=(lowerb+upperb)/2.0while(i<=12):   ...

Categories: , , , ,

Monthly Payment of a Credit Card

#Python #Program to calculate minimum Monthly Payment of a Credit Cardbalance = 3329annualInterestRate = 0.2minimumMonthlyPay=100newbalance=balancei=1monthlyInterestRate=annualInterestRate/12.0while(i<=12):    monthlyUnpaidBal=newbalance-minimumMonthlyPay    newbalance=monthlyUnpaidBal+monthlyInterestRate*monthlyUnpaidBal   ...

Categories: , , ,

Receipt of Credit Card

#Python #Program to calculate receipt of a Credit Card balance = 4842annualInterestRate = 0.2monthlyPaymentRate = 0.04totalPaid=0.0 i=1while(i<=12):    monthlyInterestRate=annualInterestRate/12.0    minimumMonthlyPay=monthlyPaymentRate*balance    monthlyUnpaidBal=balance-minimumMonthlyPay   ...

Categories: , ,

Tower of Hanoi

#Python ''' Recursive program to implement Tower of Hanoi for n rings and 3 stacks ''' def printMove(fr, to):    print('move from ' + str(fr) + ' to ' + str(to))def Towers(n, fr, to, spare):    if n == 1:        printMove(fr, to)    else:       ...

Categories: , ,

Semordnilap using Recursion

#PYTHON '''A semordnilap is a word or a phrase that spells a different word when backwards ("semordnilap" is a semordnilap of "palindromes"). Here are some examples:    nametag / gateman    dog / god    live / evil    desserts / stressed  Recursive program, semordnilap, that takes...

Categories: , , ,

19 Jan 2015

Longest substring in Alphabetical order

#Python ''' Find the longest substring in alphabetical order in the given string ''' s = 'azcbobobegghakl' i=1subs=s[0]subs2=s[0]while(i<len(s)):    j=i    while(j<len(s)):        if(s[j]>=s[j-1]):            subs+=s[j]           ...

Categories: , ,

Count of Substring in String

#Python ''' Count the number of times the substring 'bob' appears in string s ''' s='azcbobobegghakl'i=0ocr=0while(i<(len(s)-2)):    ocr+=s.count('bob',i,i+3)    i+=1       print "Number of times bob occurs is:", ocr     ...

Categories: ,

Counting Vowels

#Python ''' The program counts number of vowels in a string s ''' s = 'azcbobobegghakl' s=s.lower()count=0i=0while (i<len(s)):    if (s[i] in 'aeiou'):        count+=1    i+=1print "Number of vowels", count    &nbs...

Categories: , ,

Number Guessing game

#Python ''' Number Guessing Game '''   print "Please think of a number between 0 and 100!"start=0end=100guess=50while(1):    print "Is your secret number",guess, "?"    rd=raw_input("Enter 'h' to indicate the guess ls too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")   ...

Categories: , , ,

Copyright © 2025 UPgradeCODING | Powered by Blogger